在 Mongo Compass 上通过 ObjectId 进行搜索

如何使用 Mongo Compass 并通过 ObjectID 进行搜索?我一直在找关于这个的文件,但是一无所获。我试过了:

{ "_id" : "58f8085dc1840e050034d98f" }


{ "$oid" : "58f8085dc1840e050034d98f" }


{ "id" : "58f8085dc1840e050034d98f" }

这些似乎都不管用,而且越来越令人沮丧。另外,请注意-在 Compass 中显示文档时是否可以设置跳过/限制?

先谢谢你!

70313 次浏览

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.

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")}

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

{module_id: ObjectId('5cee65f283774d3470fc01cc')}

Search Result: search result