user3787092 user3787092 - 1 month ago 5x
Python Question

pymongo+MongoDB: How to find _id in pymongo?

I want to find the

of a document of a collection
. I have inserted the document but want to find the
of document. Is it possible ? I am trying as

result = db.mycol.find({"_id": {"name": "John"}})

But it is returning a cursor object.

pymongo.cursor.Cursor object at 0x00000000030E3DD8>

Then I tried as

for itm in result:
print (itm)

But it is not printing anything.


Try it like that

result = db.mycol.find({"name": "John"})
for item in result:

Just have a look at the docs to see how to use pymongo