user3787092 user3787092 - 1 year ago 170
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download