我正在尝试全局修复一些数据...为什么会出现此错误...TypeError: Object function model(doc, fields, skipId) { if (!(this instanceof model)) r
我正在获取所有数据,它应该更新,但不是。并且错误是钝的。
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" }})