(name, delta=1)
atomically change a global int64 counter and return the newest value;
    starting from 1
    mongo document structure:
    {
        _id: counter name
        val: current value
    }
atomically change a global int64 counter and return the newest value;
    starting from 1
    mongo document structure:
    {
        _id: counter name
        val: current value
    }
atomically change a global int64 counter and return the newest value ; starting from 1 mongo document structure : { _id : counter name val : current value }
def global_counter(name, delta=1):
    """ atomically change a global int64 counter and return the newest value;
    starting from 1
    mongo document structure:
    {
        _id: counter name
        val: current value
    }"""
    db = get_mongo('global_counter')
    rst = db.find_and_modify(query={'_id': name},
                            update={'$inc': {'val': delta}},
                            new=True)
    if rst:
        k = rst.get('val')
        if k:
            return k
    try:
        val = long(1)
        db.insert({'_id': name, 'val': val})
        return val
    except DuplicateKeyError:
        return global_counter(name, delta)
def global_counter ( name , delta = 1 ) : db = get_mongo ( 'global_counter' ) rst = db . find_and_modify ( query = { '_id' : name } , update = { '$inc' : { 'val' : delta } } , new = True ) if rst : k = rst . get ( 'val' ) if k : return k try : val = long ( 1 ) db . insert ( { '_id' : name , 'val' : val } ) return val except DuplicateKeyError : return global_counter ( name , delta )