PyMongo find_one() returns nothing when passed _id as query parameter
To add to the @Simulant answer, you need to import the ObjectId
from the bson.objectid
:
from bson.objectid import ObjectId
x = db.collection.find_one({"_id": ObjectId("569bbe3a65193cde93ce7092")})
pass it without the quotes on the content of _id
you also need to import ObjectId
.
from bson.objectid import ObjectId
{"_id": ObjectId("569bbe3a65193cde93ce7092")}
If you pass it with quotes you are searching for an Object with the String ObjectId("569bbe3a65193cde93ce7092")
as ID. But in MongoDB the ID is an Object and not a String. Thats a difference.