猫鼬中的.in()和all.()运算符有什么区别? [英] What's difference between .in() and all.() operators in mongoose?

查看:89
本文介绍了猫鼬中的.in()和all.()运算符有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是好奇猫鼬查询中.in()和.all()方法之间的区别是什么? 你能用一个简单的例子来解释吗?

I'm just curious what's difference between .in() and .all() methods in mongoose Query? Can you explain by a simple example.

推荐答案

以下是mongodb.org的解释:

Here is the explanation from mongodb.org:

$ all

$ all运算符类似于$ in,但是必须匹配数组中的所有值,而不是匹配指定数组中的任何值.例如,对象

The $all operator is similar to $in, but instead of matching any value in the specified array all values in the array must be matched. For example, the object

{a:[1,2,3]}

{ a: [ 1, 2, 3 ] }

将与

db.things.find({a:{$ all:[2,3]}});

db.things.find( { a: { $all: [ 2, 3 ] } } );

但不是

db.things.find({a:{$ all:[2,3,4]}});

db.things.find( { a: { $all: [ 2, 3, 4 ] } } );

一个数组可以包含比$ all条件指定的元素更多的元素. $ all指定必须匹配的最小元素集.

An array can have more elements than those specified by the $all criteria. $all specifies a minimum set of elements that must be matched.

此处

这篇关于猫鼬中的.in()和all.()运算符有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆