I have a Mongoose schema with a field of type array, intended for containing several strings:
const exampleSchema = new.mongooseSchema({
field1: String,
field2: String,
field3: [String]
})
I am setting up the backend to concatenate/push new strings into the field3 array, hoping to get something like this:
{
field1: 'some string',
field2: 'some other string',
field3: [
'string inside array1',
'string inside array2',
'string inside array3',
]
}
I am trying to do this with findByIdAndUpdate() an was trying things like spread operators to concatenate new strings into field 3, but I am not fully sure of how to use the syntax.
Is there any clean way of doing this without having to create an new updated object to replace the entire document?