比较MongoDB中的多个属性?
要比较多个属性,请使用$where运算符。首先让我们创建一个包含文档的集合-
> dbcomparingMultiplePropertiesDemoinsertOne({"Values":[10,70,60]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5cf228fcb64a577be5a2bc0a")
}以下是在find()方法的帮助下显示集合中所有文档的查询-
> dbcomparingMultiplePropertiesDemofind()pretty();
这将产生以下文件-
{
"_id" : ObjectId("5cf228fcb64a577be5a2bc0a"),
"Values" : [
10,
70,
60
]
}情况1:如果条件变为true,则将获得一个数组,否则将不会显示任何内容。下面是查询以比较MongoDB中的多个属性。
> dbcomparingMultiplePropertiesDemofind({ $where : "thisValues[1] > thisValues[2]" });由于70>60-这将产生以下文件-
{ "_id" : ObjectId("5cf228fcb64a577be5a2bc0a"), "Values" : [ 10, 70, 60 ] }情况2:如果条件变为假,则什么都不会显示以下是查询以比较MongoDB中的多个属性-
> dbcomparingMultiplePropertiesDemofind({ $where : "thisValues[1] < thisValues[2]" });对于错误条件,由于70<60为假,因此不会显示数据。
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短