Reputation: 1884
i want to update nested mongo document with for loop here is my node.js code;
//loop starts
var update = {
"rate":mainRate,
"classifierCategories."+e+".rate":temiz[i].slice(0,2)
};
classifier.update({"classifierShortName":arrFile[1]},update,function(err){
console.log("updated - "+i+" - "+e);
});
//loop end
Error accurs ;
Unexpected token +
How can i update classifierCategories array with for loop
Upvotes: 0
Views: 109
Reputation:
Your problem is how you are trying to notate the object "keys". This isn't valid for key construction in JavaScript object as the key names are literal and all characters are considered part of the name string.
Notate like this instead:
var update = { "rate": minRate };
update["classifierCategories."+e+".rate"] = temiz[i].slice(0,2);
That allows you to dynamically assign the key name like you want.
Upvotes: 2