'Can not find a record by it's _id in mongoDB
I want to get a record by its _id like this:
db.user.find({_id : ObjectId("53a095aa4568cb1fef93f681")})
As you can see the record exists:

I think my way is correct according to:
- Why am I unable to find a record by _id in mongodb
- how do I search for an object by its ObjectId in the console?
- Is it ok to use Mongo's "Object ID" as its unique identifier? If so, how can I convert it to a string and look it up by string?
So what's wrong with my code? I'm using RoboMongo.
Solution 1:[1]
If you are using python, Try this,
from bson import ObjectId
db.user.find({_id : ObjectId("53a095aa4568cb1fef93f681")})
Solution 2:[2]
Sometime it is right to find _id as a str, sometime it is right to find _id as an ObjectId, it depends on where you are.
a. NoSQLBooster/Pymongo:
db.user.find({_id : ObjectId("53a095aa4568cb1fef93f681")})
b. Robo3T/RoboStudio
db.user.find({_id : "53a095aa4568cb1fef93f681"})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shirantha Madusanka |
| Solution 2 | K. Symbol |
