How to update a document in an array?

Hi!

These are my structs:

type Home struct {
	ID         primitive.ObjectID `json:"id" bson:"_id"`
	Name       string             `json:"name" bson:"name"`
	Location   string             `json:"location" bson:"location"`
	Rooms      []Room             `json:"rooms" bson:"rooms"`
}

type Room struct {
	ID              primitive.ObjectID   `json:"id" bson:"_id"`
	Name            string               `json:"name" bson:"name"`
	Floor           int                  `json:"floor" bson:"floor"`
}

This is my collection:

{
		"_id": "611ed1a7e81cf2e4879a73f8",
		"name":"blablabla",
		"location":"New York",
		"rooms":[
			{
				"_id":"611ed1a7e81cf2e4879a7399",
				"name":"test1",
				"floor":3
			},
			{
				"_id":"611efbb06986120738b4092f",
				"name":"test2",
				"floor":5
			}
		]
	}

I want to update the element with _id = 611efbb06986120738b4092f with this:

{
  ...
  "name":"test2_updated",
  "floor": 90
}

How can I do this?

Thank you.

My current solution is:

filter := bson.D{primitive.E{Key: "_id", Value: objectId}}
arrayFilters := options.ArrayFilters{Filters: bson.A{bson.M{"x._id": objectRid}}}
    upsert := true
    opts := options.UpdateOptions{
    	ArrayFilters: &arrayFilters,
     		Upsert:       &upsert,
    }
    update := bson.M{
    	"$set": bson.M{
    		"rooms.$[x].name": newName,
    		"rooms.$[x].floor": newFloor
           },
    }
    ret, err := collection.UpdateOne(handler.ctx, filter, update, &opts)

Do you have suggestions to improve my current solution? Is there a cleaner/shorter way to do this?