0

I got this document in a collection

{ 
    "_id" : ObjectId("1234"), 
    "title" : "Some Company", 
    "assignedPackages" : [
        ObjectId("2345"), 
        ObjectId("3456"), 
        ObjectId("4567")
    ]
} 

and this updateMany

db.getCollection("companies").updateMany(
    {  _id: ObjectId("1234"), "assignedPackages": ObjectId("2345")},
    { $set: { "assignedPackages.$[elem]" : ObjectId("5432") }}, // , "updatedAt": "$$NOW"  
    { arrayFilters: [ { "elem": ObjectId("2345") } ] }
)

When I run it it acknowledges the run and says 0 matched and updated. What am I doing wrong?

  • 1
    your query looks good, if it returns 0 match then, make sure your collection having `{ _id: ObjectId("1234"), "assignedPackages": ObjectId("2345")},` exact values. – turivishal Jun 10 '21 at 15:33
  • Thanks for the quick reply and confirmation this should work @turivishal! I checked and double checked that and it seems to be ok. I did find on that _id and that assignedPackages object and it finds them perfectly. It may have something to do with the new version of Studio3T that got installed couple of days ago. Last week I tried this update last week and it worked fine. Studio3T updated itself to 2021.3.1 (from 2021.3.0 I think) and it does not seem to work. It could be I am making a booboo, just cannot find it. I am going to try Compass and see if that works – Robert Bartelds Jun 11 '21 at 14:20

0 Answers0