2
爲什麼會發生這種情況?這種差異是否有合理的解釋?在mongodb shell和node.js中查詢的行爲不同
例如我有一個db結構爲;
{
id: "1"
category: {
name: "name1"
groups: [
{
groupName : "groupName1"
title: ""
},
{
groupName : "groupName2"
title: ""
}
]
}
}
查詢如下;
db.collection.aggregate({$unwind:"$category.groups"},
{$match:{"category.groups.groupName": "groupName2",
"category.name" : "name1"}})
在mongo shell中它返回爲;
{
id: "1"
category: {
name: "name1"
groups: [
groupName : "groupName2"
title: ""
]
}
}
Query in node.js;
db.collection.aggregate({$unwind:"$category.groups"},
{$match:{"category.groups.groupName": "groupName2",
"category.name" : "name1"}}).
toArray(function(err, result) {
if (result) {
debugger;
var res = result;
}
});
};
其中在node.js結果是類似的;
{
id: "1"
category: {
name: "name1"
groups: [
{
groupName : "groupName1"
title: ""
},
{
groupName : "groupName2"
title: ""
}
]
}
}
你可以提供一個示例查詢,這是表現這種方式.. –
有什麼區別,你應該更明確 –
我編輯我的問題,謝謝你的建議。 –