猫鼬中的.in()和all.()运算符有什么区别?

编程入门 行业动态 更新时间:2024-10-27 08:27:15
本文介绍了猫鼬中的.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的解释:

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.()运算符有什么区别?

本文发布于:2023-11-23 19:29:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622616.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   运算符   猫鼬中

发布评论

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

>www.elefans.com

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