addToSet
.
const newListValues = ['I am a string inside an array.'];
MyCollectionModel.findByIdAndUpdate(
_someId,
{
arrField: newListValues
},
{ new: true }
);
如果
newListValues
不是数组,在尝试设置它之前,需要将新值设置为数组。
const newListValues = 'I am a string';
MyCollectionModel.findByIdAndUpdate(
_someId,
{
arrField: [newListValues]
},
{ new: true }
);