Answer the question
In order to leave comments, you need to log in
How to properly update data in MongoDB?
Hello. The data is stored in this way
{
id: //,
list: ['one', 'two', 'three']
}
Answer the question
In order to leave comments, you need to log in
$push just adds the data to the array
$addToSet adds with the replacement
tag = ['four', 'five']
db.collection.update({searchtags: "anything"}, {$push: {tag: ['one', ' two', 'three', 'four']}})
tag = ['one', 'two', 'three', 'four', 'four', 'five']
db.collection.update({searchtags: "anything"}, {$addToSet: {tag: ['one', 'two', 'three', 'four']}})
tag = ['one', 'two', 'three', 'four' , 'five']
Through a dot, you can push directly into the array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question