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);
2.1m questions
2.1m answers
60 comments
56.9k users