这是我的数据
// Data 1
{
name : 111,
factors :
[
{name:"f1", value:"dog", unit : "kg"},
{name:"f2", value:"0"},
{name: "f3", value:"rain"}
]
},
// data2
{
name : 112,
factors :
[
{name:"f1", value:"cat", unit : "g"},
{name:"f2", value:"13"},
{name: "f3", value:"rain"}
]
}
// more data ...
我想找到一个f3=rain
和f1=cat
。
我试过了
query = {
factors : {
$elemMatch :
[
{name: "f1", value:"cat"},
{name: "f3", value: "rain"}
]
},
但有错误说,
Error: error: { "$err" : "$elemMatch needs an Object", "code" : 12517 }
我该怎么做才能构建该查询?