node.js - How to use variable mongoose query? -
data schema
id: string, item: { possess: { jewel: [number] }
code
var temp = 1 db.collection.update({"id":"sample"},{"$set":{"item.possess.jewel.1":888})
how use variable temp in "item.possess.jewel.1" ?
"item.possess.jewel.temp" doesn't work
you have build $set
object programmatically:
var temp = 1; var set = {$set: {}}; set.$set["item.possess.jewel." + temp] = 888; db.collection.update({"id":"sample"}, set);
Comments
Post a Comment