H, I have a document with an array, here is the structure:
{
_id:"...",
_artist:"...",
_datecreated:"...",
_gallery: [0] {
_title: title,
_description: description
_datecreated: currentDate,
_client: client,
_path: displaypath,
_artworkid: artworkid,
},
_shop:"...",
_devdate:"...",
_dev:"...",
_username:"...",
_password:"...",
}
And I’ve got only one entry in the array, which is 0…
I have succeeded in updating the “_title” field within array using:
"DB.updateOne({"_gallery._artworkid": artid}, {$set: { "_gallery.0._title": newtitle }});"
But I have a problem, thats using a prefixed “.0.” in the function, when really, I want to use that ‘field’ as a variable as in ‘i’ (depending on which ‘i’ is being chosen, the array entry will be updated accordingly), and I have tried all sorts, with no luck to simply include a variable into the function “field” option… Can someone shine a light on this?
This example bellow illustrates what I mean with the ‘i’, there is the same: “array”.“entrynr”.“field”…
I got errors of this sort:
- "SyntaxError: Unexpected token ‘+’ "
- MongoServerError: Modifiers operate on fields but we found type string instead. For example: {$mod: {: …}} not {$set: “_gallery.0._title: B Again”}
a bunch more, but this was as close as I got to it…
How can I do this?
HELP x)