Answers for "mongoose update array in object"

1

mongoose modify all elements in array

// Playground: https://mongoplayground.net/p/-TgGWwBd5l-
db.collection.update({
  "_id": "password"
},
{
  "$inc": {
    "waitlist.$[].queue_place": -1
  }
})

// Database
/*
[
  {
    "_id": "password",
    "waitlist": [
      {
        "_id": "adasd",
        "queue_place": 123
      },
      {
        "_id": "ada43sd",
        "queue_place": 2
      }
    ]
  }
]
*/
Posted by: Guest on January-12-2021
1

updating an array of object in mongoose

Person.update(
   {
     _id: 5,
     grades: { $elemMatch: { grade: { $lte: 90 }, mean: { $gt: 80 } } }
   },
   { $set: { "grades.$.std" : 6 } }
)
Posted by: Guest on August-23-2020
-1

mongoose update array in object

Person.findOneAndUpdate({_id: id}, 
{ 
  "$set": {[`items.$[outer].${propertyName}`]: value} 
},
{ 
  "arrayFilters": [{ "outer.id": itemId }]
},
function(err, response) {
  ...
})
Posted by: Guest on January-11-2021

Code answers related to "mongoose update array in object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language