Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Searching for Mongo ObjectIds in fields other than _id #1188
I have a document setup in my MongoDB setup like this:
I know that when you call a find based on the _id field you can just pass a string, so for example:
will return the document above. The issue I ran into was with calling a find on the match_id field. I assumed it would work similar to a find on the _id field since they were both ObjectIds, so I tried this:
I found I had to call the find using a MongoId object instead of a plain string, which in hindsight makes sense, but it would be nice to be able to search for ObjectIds based on strings alone. Is this expected behavior and are there any plans to implement a feature like this into the Model::find method?