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.

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.