pythonmongodbpymongo

Search for a document by ObjectId in mongodb with pymongo


I need to search an ObjectId with python using pymongo but I always get an error.

import pymongo
from pymongo import MongoClient
from pymongo import ObjectId

gate = collection.find({'_id': ObjectId(modem["dis_imei"])})

Any ideas how to search?


Solution

  • I use pymongo 2.4.1.

    from bson.objectid import ObjectId
    [i for i in dbm.neo_nodes.find({"_id": ObjectId(obj_id_to_find)})]