比较来自世界各地的卖家的域名和 IT 服务价格

MongoDB 财产对象 $exists 在嵌套阵列中

我在数据库集合中有以下对象结构:


{
"name" : "test",
"code" : "test",
"attributes" : [
{
"name" : "test1",
"code" : "code1"
},
{
"name" : "test2",
"code" : "code2",
"value" : true
},
{
"name" : "test3",
"code" : "code3",
"value" : ""
},
{
"name" : "test4",
"code" : "code4"
"value" : [
{
"code" : "code4.1",
"name" : "test4.1"
},
{
"name" : "test4.2"
}
]
}
]
}


因此,物业 "value" 它可以是空字符串,逻辑值,数组,甚至根本没有定义。

如何向具有非空属性数组的对象列表进行请求,也没有属性" attributes.value", 至少在数组内的单个对象内定义?

p. s. 我尝试了以下查询:


db.collection.find/{"attributes": {$exists: true, $ne: []}, "attributes.value": {$exists: false}}/


但查询的结果是空的。
已邀请:

裸奔

赞同来自:

操作员 $elemMatch 符合包含阵列字段的文档
至少有一个与所有指定的元素匹配
请求标准。

此请求适用于我:


db.getCollection/'testeur'/.find/{ "attributes": {
$exists: true,
$ne: [],
$elemMatch: { "value": {$exists: false } }
}
}/

要回复问题请先登录注册