How to import data from mongodb to pandas?

pymongo might give you a hand, followings are some codes I’m using: import pandas as pd from pymongo import MongoClient def _connect_mongo(host, port, username, password, db): “”” A util for making a connection to mongo “”” if username and password: mongo_uri = ‘mongodb://%s:%s@%s:%s/%s’ % (username, password, host, port, db) conn = MongoClient(mongo_uri) else: conn = … Read more

Can you specify a key for $addToSet in Mongo?

You can qualify your update with a query object that prevents the update if the name is already present in profile_set. In the shell: db.coll.update( {_id: id, ‘profile_set.name’: {$ne: ‘nick’}}, {$push: {profile_set: {‘name’: ‘nick’, ‘options’: 2}}}) So this will only perform the $push for a doc with a matching _id and where there isn’t a … Read more