0

I have the following in Meteor user profile:

{
  "_id": "dwdtWPFjugF3sTLmE",
  "emails": [
    {
      "address": "[email protected]",
      "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
          }
      }
    );
1
  • 2
    Also - don't use profile. Put this information somewhere else. Commented Oct 16, 2017 at 19:02

1 Answer 1

2

Your

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

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

$set: {
    'profile.tasks.$.completed': completed
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.