我只是好奇猫鼬查询中.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的解释:
Here is the explanation from mongodb:
$ 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.()运算符有什么区别?
发布评论