Example #1
0
def contar_registros():
    db = conectar('openlibrary')
    for nome in db.collection_names():
        if nome.startswith('system.'):
            continue
        colecao = getattr(db, nome)
        print '{1:10,} {0}'.format(nome, colecao.count())
from mongo_util import conectar
from bson.code import Code
from pprint import pprint

db = conectar('openlibrary')

for res in db.editions.find({'contributions':{'$exists':1}}, {'contributions':1}):
    pprint(res)
Example #3
0
#!/coding: utf-8

from mongo_util import conectar
from bson.code import Code
from pprint import pprint

db = conectar("openlibrary")

for res in db.editions.find({"authors": {"$exists": 1}}, {"authors": 1}):
    for author_fkey in res[u"authors"]:
        author = db.authors.find_one({"_id": author_fkey[u"key"]}, {"name": 1})
        if author is None:
            print author["name"]
Example #4
0
#!/coding: utf-8

from mongo_util import conectar
from bson.code import Code

db = conectar('openlibrary')

TYPE_CODES = {'object': 1, 'array': 2, 'string': 4, 'number': 8}

MAP = Code('''function () {
    var type_codes = %r;
    var type = '';
    for (field_name in this) {
        type = typeof this[field_name];
        if (type === 'object') {
            type = this[field_name] instanceof Array ? 'array' : 'object';
        }
        emit(field_name, type_codes[type])
    }
}''' % TYPE_CODES)

REDUCE = Code('''function (key, values) { 
    var types = 0;
    values.forEach(function(type_code) { types |= type_code; });
    return types;
}''')


def count_fields(collection):
    return db[collection].map_reduce(MAP, REDUCE, "field_types").find()
def contar_registros():
    db = conectar('test')
    print db.dup_test.count(), 'registros efetivamente salvos'
    for r in db.dup_test.find():
        pprint(r)