0
我想解決一些全球數據...爲什麼我得到這個錯誤... TypeError:對象函數模型(doc,fields ,skipId){if(!(this instanceof model))mongodb ... Mongoose更新嵌套集...爲什麼這麼難arg
我得到所有的數據,它應該更新,但它不是。並且錯誤是鈍的。
UpdateAllThings: function(req, res) {
things.find().exec(function(err, items) {
items.forEach(function(th) {
th.Features.forEach(function(f) {
thingsfeatures.findOne({'fName': f.fName},function(err, item) {
if (item != null) {
try{
things.Update({Features: {"$elemMatch":{_id:f._id}}}, {$addToSet: {'Features.$.tType': item.tType, 'Features.$.fGroup': item.fGroup }}, function (err, inventory) {
if (err) return handleError(err);
});
}catch(err){
if (err) return handleError(err);
}
}
});
});
});
});
return res.send('thanks please come again');
}
* _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ *
當然:這或多或少它....
{
"Features" : [{
"_id" : ObjectId("5013c9742df16337609b2706"),
"tID" : "5013c9742df16337609b26f4",
"tName" : "Canon EOS T2i (Rebel T2i, Canon 550D) ",
"fName" : "Retail Price:",
"fValue" : "899.99",
"_keywords " : ["899.99"]
}, {
"_id" : ObjectId("5013c9742df16337609b2707"),
"_keywords " : ["1", "x", "Proprietary", "LP-E8", "Lithium-ion", "rechargeble"],
"fGroup" : ["Power"],
"fName" : "Batteries Included:",
"fValue" : "1 x Proprietary LP-E8 Lithium-ion rechargeble",
"tID" : "5013c9742df16337609b26f4",
"tName" : "Canon EOS T2i (Rebel T2i, Canon 550D) ",
"tType" : ["Cammera"]
}],
"_id" : ObjectId("5013c9742df16337609b26f4"),
"tName" : "Canon EOS T2i (Rebel T2i, Canon 550D) ",
"tType" : "Camera"
}
這個工作,但它與數據,而不僅僅是新的領域,因爲我想數據數組添加。
db.things.update({"_id":ObjectId("5013c9742df16337609b26f4"), "Features._id" : ObjectId("5013c9742df16337609b2706") }, { $addToSet : { "Features.$.fType" : "Cammera", "Features.$.fGroup" : "Power" }})
一個問題,我看到:'things.Update'應該是'things.update' – JohnnyHK
哈哈,讓我們看看一個狗孃養的....感謝 – athingsiathing
的太陽。感謝johnny ... Arg我討厭區分大小寫的語言。 – athingsiathing