Sample document:
{
_id: 376818,
buildingName: "test building",
fuelTypeList: [
{
_id: 376820,
buildingId: 376818,
type: "Natural Gas"
},
{
_id: 376821,
buildingId: 376818,
type: "District Cooling"
}
]
}
I want to add a new field “id” to every item in fuelTypeList. I am using MongoDB Compass (Version 1.39.4 (1.39.4) ) MONGOSH terminal to run the command.
This is my query
db.building.updateOne(
{ _id: 376818 },
{ $set: { fuelTypeList.$[].id: 5 } }
);
and I am getting error
Error: clone(t={}){const r=t.loc||{};return e({loc:new Position("line"in r?r.line:this.loc.line,"column"in r?r.column:...<omitted>...)} could not be cloned.
According to https://www.mongodb.com/docs/manual/reference/operator/update/positional-all/, $ should be supported. What is wrong here?