0

I have the following in Meteor user profile:

{
  "_id": "dwdtWPFjugF3sTLmE",
  "emails": [
    {
      "address": "armin@four1five.com",
      "verified": false
    }
  ],
  "profile": {
    "name": "Armin",
    "tasks": [
      {
        "task": "Task one",
        "completed": false,
        "created": "2017-10-16T18:48:21.331Z"
      },
      {
        "task": "Task Two",
        "completed": false,
        "created": "2017-10-16T18:48:25.898Z"
      }
    ]
  },
  "username": "armin"
}

How do i query by "created", and update the "completed" field? or what is wrong with my approach:

Meteor.users.update(
      { _id: Meteor.userId(), "profile.tasks.created": created },
      {
          $set: {
              'profile.tasks.completed': completed
          }
      }
    );
Armin Masoomi
  • 125
  • 1
  • 9
  • 2
    Also - [don't use profile](https://guide.meteor.com/accounts.html#dont-use-profile). Put this information somewhere else. – chazsolo Oct 16 '17 at 19:02

1 Answers1

2

Your

$set: {
    'profile.tasks.completed': completed
}

should be using the positional operator '$' like so:

$set: {
    'profile.tasks.$.completed': completed
}
dnickless
  • 10,733
  • 1
  • 19
  • 34