Mongodb Object Key With Es6 Template String
I'm trying to update an array in my collection with this: var str = 'list.0.arr'; db.collection('connect').update({_id: id}, {$push: { `${str}`: item}}); This exact string
Solution 1:
Template literals cannot be used as key in an object literal. Use a computed property instead:
db.collection('connect').update({_id: id}, {$push: {[str]: item}});
// ^^^^^
See also Using a variable for a key in a JavaScript object literal
Post a Comment for "Mongodb Object Key With Es6 Template String"