Hello @mystery_bbs, welcome to the MongoDB Community forum!
What I wanted to do: update the particular step of a particular region.
To update a nested array based upon a condition matching the nested array element’s field, you need to use the arrayFilters option of the UpdateOne operation .
The UpdateOne method takes the arguments: ctx, filter, update and opts. There are two UpdateOptions you are working with; these are the Upsert and the ArrayFilters. The code for update options can look like this in your case.
// Create an instance of an options and set the desired options
upsert := true
arrayFilters := options.ArrayFilters{ // .... }
updateOpts := options.UpdateOptions{
ArrayFilters: &arrayFilters
Upsert: &upsert
}
And, use the update options:
ret, err := collection.UpdateOne(ctx, filter, update, &updateOpts)
Your filter field still requires a definition - it needs to be based upon what you want to filter upon. I think you want to filter upon the objID. Then the filter would be:
filter := {bson.M{"_id": objID}
For usage of array filters see this post (with native code, not golang): Updating nested array of objects using $addToSet