-1
"ID": 254252324242423
"objList" : [{
    "Date":3-6-2013,
    "Times": ["16:34-17:54", "18:00-19:00"]
},{
    "Date":3-7-2013,
    "Times": ["16:34-17:54", "18:23-19:00"]
},{
    "Date":3-8-2013,
    "Times": ["16:34-17:54", "18:30-20:00"]
}]

I don't know how to add an element to the array of an object from the list with a specific date.

2

1 Answer 1

1

this is a way i have found Two possibilities here:

Since you don't have an unique identifier for the comments, the only way to update an specific item on the comments array is to explicitly indicate the index you are updating, like this:

db.documents.update(
  { _id: "iL9hL2hLauoSimtkM"},
  { $push: { "comments.0.likes": "userID3" }}
);

If you add an unique identifier for the comments, you can search it and update the matched item, without worrying with the index:

db.documents.update(
  { _id: "iL9hL2hLauoSimtkM", "comments._id": "id1"},
  { $push: { "comments.$.likes": "userID3" }}
);
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.