Hello.
I’ve got a nested document which has a boolean as a property and I’d like to toggle it.
I’ll attach a screenshot of the document along with the code that I am currently using
.updateOne(
{ _id: id, "items.name": "Zibby" },
{ $set: { "items.$.bought": true } }
)
I have tried these solutions that I found on stackoverflow:
.findOneAndUpdate(
{ _id: id, "items.name": "Zibby" },
{ $set: { "items.$.bought": { $not: "items.$.bought" } } }
)
I get the following error:
MongoServerError: Invalid $set :: caused by :: FieldPath field names may not start with ‘$’.
.findOneAndUpdate({ _id: id, "items.name": "Zibby" }, [
{ $set: { "items.$.bought": { $eq: [false, "items.$.bought"] } } },
])
With the same error