流星集合使用find选择器来区分某些变量(Meteor Collections using find selector to discriminate against certain variable

编程入门 行业动态 更新时间:2024-10-11 17:28:34
流星集合使用find选择器来区分某些变量(Meteor Collections using find selector to discriminate against certain variable)

我知道我们可以在选择器中使用find来获取集合中的特定元素,如下所示:

usernames.find(selector)

要指定查找具有特定属性(如“Bob”)的所有用户名作为我将执行的名称:

usernames.find({name: "Bob"})

这只会显示名为Bob的文档。 但是让我们说,我的收藏中还有其他人喜欢Alice和Kat,我想找到收藏中不是Bob的所有人。

我将如何指定一个选择器来查找名称不是Bob的用户名集合中的所有内容?

我试过了:

usernames.find({name: !"Bob"})

我被困在语法上。 谢谢!

I understand we can use find with the selector to get specific elements in a collection like so:

usernames.find(selector)

To specify finding all usernames with a specific property like "Bob" as the name I would do:

usernames.find({name: "Bob"})

Which would only show me documents that have the name Bob. But let's say there are other people in my collection like Alice and Kat and I want to find everyone in the collection whose name is not Bob.

How would I specify a selector to find everything in the usernames collection whose name is not Bob?

I've tried:

usernames.find({name: !"Bob"})

I'm stuck on the syntax. Thank you!

最满意答案

使用$ ne运算符

usernames.find( { name: { $ne: "Bob" } })

$ ne选择字段值不等于指定值的文档。 这包括不包含该字段的文档。

https://docs.mongodb.com/manual/reference/operator/query/ne/

Use $ne operator

usernames.find( { name: { $ne: "Bob" } })

$ne selects the documents where the value of the field is not equal to the specified value. This includes documents that do not contain the field.

https://docs.mongodb.com/manual/reference/operator/query/ne/

更多推荐

本文发布于:2023-07-26 06:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1271993.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   流星   选择器   find   Meteor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!