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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -