find record in mongodb with mongodb object id python 1

find record in mongodb with mongodb object id python

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

Here is what the above code is Doing:
1. We’re using the find() method to find all documents in the neo_nodes collection.
2. We’re using the ObjectId() method to convert the string obj_id_to_find to an ObjectId object.
3. We’re using a list comprehension to iterate through the results of the find() method.

Similar Posts