mongodb 在 Mongo Compass 上按 ObjectId 搜索

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43525523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:56:48  来源:igfitidea点击:

Searching by ObjectId on Mongo Compass

mongodbmongodb-querymongodb-compass

提问by aamirl

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:

如何使用 Mongo Compass 并通过 ObjectID 进行搜索?我一直在为此寻找文档,但没有取得任何成功。我试过了:

{ "_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?

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

Thanks in advance!

提前致谢!

回答by helmy

UPDATENewer versions of Compass now support querying ObjectId similar to how they would be queried via the mongo shell (the $oidsyntax will notwork in these newer versions):

UPDATE较新的指南针的版本现在支持查询OBJECTID方式类似于他们将通过蒙戈外壳进行查询(该$oid语法将不会在这些新版本的工作):

{_id: ObjectId('58f8085dc1840e050034d98f')}

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

如果您使用的是 1.10.x 之前的旧版本,请在查询框中输入以下内容:

{"_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.

还值得指出的是,在 UI 中,您可以单击 _id 之一,它将根据您单击的内容自动填充查询框。您还可以通过 shift+单击多个字段来创建复合(和-ed)查询条件,或者您可以单击并拖动以选择一个范围。

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

跳过和限价是版本> = 1.8.x的支持,在文档选项卡下浏览时支持跳过和限制。单击查询栏右侧的“选项”按钮。有关说明和详细信息,请参阅查询栏文档。

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

Schema 选项卡仅支持限制,因为这将对文档进行抽样,而在该上下文中跳过实际上没有意义。

In order to click on the _ids you need to be on the Schematab. 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.

为了单击 _ids,您需要在Schema选项卡上。如果您的 _id 是 ObjectId 类型,分布的可视化将显示为日期范围,您可以拖过一行或多行以根据 _id 填充查询。如果您的 _id 是其他类型,它们的某些部分将单独显示,您可以单击、拖动或按住 Shift 键单击它们。

回答by jpoveda

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

当前版本的 MongoDB Compass (1.10.5) 似乎不再支持$oid,但它确实适用于标准查询:{"_id":ObjectId("5a028baa2dc80f2e26a8ed63")}