比较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为假,因此不会显示数据。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短