As I work on setting up basic searches in MongoDB, I have encountered a problem. I can locate records by "ObjectId," but I am unable to search by "_id." My searches are conducted directly in the Mongo console and through code written in Atom, which is then executed on a nodemon server.
db.collection.find( { ObjectId( _id: "abcdefg" ) } ) // Returns a result
db.collection.find( { _id: "abcdefg" } ) // Returns null
The issue: When entering search (1) in the console, it returns a result. However, when performing the same search in Atom and running it through nodemon, an error is thrown because "ObjectId" is undefined. Search (2) consistently returns null, regardless of where it is entered.
Are there any solutions or workarounds to address this challenge? Thank you!