Searching by ObjectId on Mongo Compass

MongodbMongodb QueryMongodb Compass

Mongodb Problem Overview


How does one use Mongo Compass and search by ObjectID? I've been searching for the documentation for this but haven't been successful with anything. I have tried:

{ "_id" : "58f8085dc1840e050034d98f" }

{ "$oid" : "58f8085dc1840e050034d98f" }

{ "id" : "58f8085dc1840e050034d98f" }

None of those seem to work and it's getting quite frustrating. Also, sidenote - is it possible to set the skip/limit when displaying documents in Compass?

Thanks in advance!

Mongodb Solutions


Solution 1 - Mongodb

UPDATE Newer versions of Compass now support querying ObjectId similar to how they would be queried via the mongo shell (the $oid syntax will not work in these newer versions):

{_id: ObjectId('58f8085dc1840e050034d98f')}

If you're using an older version before 1.10.x you, enter the following into the query box:

{"_id":{"$oid":"58f8085dc1840e050034d98f"}}

It's also worth pointing out that in the UI you can click on one of the _ids and it will auto-populate the query box with the query based on what you clicked. You can also shift+click on multiple fields to create compound (and-ed) query criteria, or you can click and drag to select a range.

Skip and Limit are support for versions >= 1.8.x does support skip and limit when browsing under the Documents tab. Click the "Options" button on the right side of the Query Bar. See the Query Bar docs for illustration and details.

The Schema tab only supports limit, as this will do a sampling of documents and skip doesn't really make sense in that context.

In order to click on the _ids you need to be on the Schema tab. If your _ids are of type ObjectId, the visualization of the distribution will appear as a date range and you can drag over one or more lines to populate the query based on _id. If your _ids are some other type, some portion of them will display individually and you can click, drag, or shift-click over them.

Solution 2 - Mongodb

The current version of MongoDB Compass (1.10.5) no longer appears to support $oid, but it does work with a standard query: {"_id":ObjectId("5a028baa2dc80f2e26a8ed63")}

Solution 3 - Mongodb

{"_id":ObjectId("5f8344e2a00ed7f6172a7184")}

Solution 4 - Mongodb

{module_id: ObjectId('5cee65f283774d3470fc01cc')}

Search Result: search result

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaamirlView Question on Stackoverflow
Solution 1 - MongodbhelmyView Answer on Stackoverflow
Solution 2 - MongodbjpovedaView Answer on Stackoverflow
Solution 3 - Mongodbhosam hemailyView Answer on Stackoverflow
Solution 4 - MongodbKishanView Answer on Stackoverflow