updateMany is not working with arrayFilters

Character.updateMany(
    { user: userId },
    { $set: { "regionRaid.$[element].clear": false } },
    { arrayFilters: [{ "element.clear": { $eq: true } }] }
_id : 63770ae21f37cb738724765c
user : 636231e72889df2615d636c3
name : "name"
level : 1548.33
regionRaid : 
[ region :"valtan", clear : false, id : 1 ], 
[ region :"iliakan", clear : false, id : 2 ], 
[ region :"vyakis", clear : false, id : 3 ]
DateToReset : "Wed Nov 23 2022 13:32:34 GMT+0900 "
updatedAt : "Fri Nov 18 2022 15:26:51 GMT+0900"

i want to replace all the regionRaid.clear : “true” to “false”
i tried to read all doc and reference but it can’t help me

Is your sample document

the input or the result?

If it is the input then none of clear field is true so no document is updated. If it is the result, then the code works because clear is false for all. We do know if any were true before.

Sorry, I forgot the description of that clear is updated by client’s input.
when the updateMany is excuted, clear value can be true or false.

[ region :"valtan", clear : true, id : 1 ], 
[ region :"iliakan", clear : false, id : 2 ], 
[ region :"vyakis", clear : true, id : 3 ]

i want all the clear value become false.

The shared data is not valid JSON:

mongosh > array = [ region :"valtan", clear : true, id : 1 ]
> SyntaxError: Unexpected token, expected "," (1:13)

> 1 | a = [ region :"valtan", clear : true, id : 1 ]
    |              ^

The following is the correct syntax:

mongosh > object = { region :"valtan" , clear : true, id : 1 }
< { region: 'valtan', clear: true, id: 1 }

Your updateMany() is appropriate and should work. If it does not then check your query part, may be your userId is wrong. Often people make the mistake of passing a string when an ObjectId should be used.

Hi @qkrwjdtn09 and welcome to the MongoDB community forum.

I tried to replica the update query in my local environment, and I was successfully able to update the records

> db.collection.updateMany( {}, { $set: { "regionRaid.$[].clear": false}})
{
  acknowledged: true,
  insertedId: null,
  matchedCount: 1,
  modifiedCount: 1,
  upsertedCount: 0
}
> db.collection.find()
[
  {
    _id: ObjectId("6377594b41a44b142239964a"),
    user: ObjectId("636231e72889df2615d636c3"),
    name: 'name',
    level: 1548.33,
    regionRaid: [
      { region: 'valtan', clear: false, id: 1 },
      { region: 'iliakan', clear: false, id: 2 },
      { region: 'vyakis', clear: false, id: 3 }
    ],
    DateToReset: ISODate("2022-11-23T04:32:34.000Z"),
    updatedAt: ISODate("2022-11-18T06:26:51.000Z")
  }
]

However, the above query is tested based on the sample document provided. I would recommend you to perform testing for the complete dataset.
Let us know if you have any further queries.

Regards
Aasawari