Answers for "mongoose modify all elements in array"

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

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 modify all elements in array"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language