How can I make this query use my variable instead of the hard coded 0?
let pos = 0; {$set: {'answers.0.acknowledged': data}}
You can use ES6 String Interpolation and Computed Property Names to build the key for $set:
$set
let pos = 0; let data = 'some data'; let q = {$set: {[`answers.${pos}.acknowledged`]: data}} console.log(q);
1.4m articles
1.4m replys
5 comments
57.0k users