1

Currently I have the following structure for one of my documents

Company: {
   Buildings: [{
       Users: [ { _id: ObjectID, name: String, number: String } ]
   }]
}

I'm trying to update the user's name and number and currently have tested and verified the following query in mongo:

db.companies.update(
    { "_id": companyID, "buildings._id": buildingID, "buildings.users._id": userID }
    , 
    { $set: { "buildings.$.users.0.name": "A new name for the user" } }
);

This query updates correctly however when I run the same exact query using mongoose

Company.findOneAndUpdate(
  { _id: companyID, "buildings._id": buildingID, "buildings.users._id": userID }
  ,
  { $set: { "buildings.$.users.0.name": newName }})

I get no error but the update is not performed.

Is the updating of a deep nested array not available on Mongoose?

1 Answer 1

1

Answer was found in an alternative answer to this question:

Answer: https://stackoverflow.com/a/28952991/1327815

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.