Учитывая совокупность пользователей:MongoDB: добавить атрибут поддокумента
db.users.insertMany(
[
{
_id: 1,
name: "sue",
points: [
{ points: 85, bonus: 20 },
{ points: 85, bonus: 10 }
]
},
{
_id: 2,
name: "bob",
points: [
{ points: 85, bonus: 20 },
{ points: 64, bonus: 12 }
]
}]);
Как добавить атрибут bonus_raw
в каждом points
, с копией значения bonus
значения? Я пробовал:
db.getCollection('users').update({ },
{$set:{ 'points.$.bonus_raw' : 'points.$.bonus' }}, false, true)
, но я получаю:
Позиционный оператор не нашел матч, необходимый из запроса. Unexpanded update: points. $. Bonus_raw