在 MongoDB Compass 中查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46113376/
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:58:32  来源:igfitidea点击:

Querying in MongoDB Compass

mongodb

提问by GBT97

Just a quick question I hope someone can answer for me.

只是一个简单的问题,我希望有人可以为我解答。

I have a collection in MongoDB containing 84 thousand documents. The data looks something like this:

我在 MongoDB 中有一个包含 84,000 个文档的集合。数据看起来像这样:

Data

数据

There are several thousand documents containing the word "BOND" as the category name such as this:

有几千个包含单词“BOND”作为类别名称的文档,例如:

More Data

更多数据

Even More Data

更多数据

And many thousands more...

还有成千上万...

Currently in MongoDB Compass I am using the following query:

目前在 MongoDB Compass 我使用以下查询:

{ "Category" : "BOND" }

But of course this just returns 1 document that where the Category is BOND.

但是当然这只会返回 1 个文档,其中类别是 BOND。

Can anybody tell me how I can query to find all documents where the field name "Category" contains the word "BOND" within it?

谁能告诉我如何查询以查找字段名称“类别”中包含“BOND”一词的所有文档?

Many thanks, G

非常感谢,G

回答by Alexey Sviridov

You should use regexp for this, i.e.

您应该为此使用正则表达式,即

{ "Category" : /^BOND.*/ }

for categories begins with BOND, or

对于以 BOND 开头的类别,或

{ "Category" : /.*BOND.*/ }

for categories contains BOND within

对于类别包含 BOND