I've found this question answered for C# and Perl, but not in the native interface. I thought this would work:
db.theColl.find( { _id: ObjectId("4ecbe7f9e8c1c9092c000027") } )
The query returned no results. I found the 4ecbe7f9e8c1c9092c000027 by doing db.theColl.find()
and grabbing an ObjectId. There are several thousand objects in that collection.
I've read all the pages that I could find on the mongodb.org website and didn't find it. Is this just a strange thing to do? It seems pretty normal to me.
Not strange at all, people do this all the time. Make sure the collection name is correct (case matters) and that the ObjectId is exact.
Documentation is here
> db.test.insert({x: 1}) > db.test.find() // no criteria { "_id" : ObjectId("4ecc05e55dd98a436ddcc47c"), "x" : 1 } > db.test.find({"_id" : ObjectId("4ecc05e55dd98a436ddcc47c")}) // explicit { "_id" : ObjectId("4ecc05e55dd98a436ddcc47c"), "x" : 1 } > db.test.find(ObjectId("4ecc05e55dd98a436ddcc47c")) // shortcut { "_id" : ObjectId("4ecc05e55dd98a436ddcc47c"), "x" : 1 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With