1

I need to be able to push new objects to fameTotals. Having a bit of trouble, thanks!

This is what the document would look like in my database:

{
  clanName: null,
  clanTag: null,
  players: [
    {
      name: null,
      tag: null,
      fameTotals: [ //PUSH TO THIS ARRAY
        {fame: 0, clanTrophies: 0, date: ''}
      ]
    }
  ]
}

I've been trying to figure it out with updateOne() and the $push operator.

Apehk
  • 25
  • 1
  • 5

1 Answers1

0

Check this example

db.collection.update({
  _id: 1
},
{
  $push: {
    players: {
      name: "yyy",
      tag: "bbbb",
      fameTotals: [
        {
          fame: 1,
          clanTrophies: 1,
          date: "27-7-21"
        }
      ]
    }
  }
})

Mongoplayground

Selva Mary
  • 658
  • 1
  • 4
  • 17