1

My model:

Restaurant = mongoose.Schema(
  name: String
  menuItems: [
    name: String
    dishes: [
      name: String
    ]
  ] 
)

I'll need to push item to 'dishes' array:

Restaurant.update {id: restID, 'menuItems.id': menuItemID}
                  $addToSet: {'menuItems.$.dishes': newDish}
                  (err, res) ->
                     ...

But nothing happens. What I'm doing wrong? Thanks for any advise.

1
  • did u figured it out? trying to do the same here Commented Mar 28, 2017 at 4:43

1 Answer 1

1

The virtual id field can't be used when updating; you have to use the actual _id name instead:

Restaurant.update {_id: restID, 'menuItems._id': menuItemID},
                  $addToSet: {'menuItems.$.dishes': newDish}
                  (err, res) ->
                     ...
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.