0
I’m trying to update a list of objects similar to this:
var lista = [ { _id: 57ea29361b297553c99d702f,
nome: 'Meu nome',
__v: 0 },
{ _id: 57ea29371b297553c99d7031,
nome: 'Meu outro nome',
__v: 0 } ]
model.update({}, lista)
.then(function (result) {
console.log(result);
}, function (error) {
console.log(error);
});
but give me that back:
{ Okay: 0, n: 0, nModified: 0 }
if you pass only one of the list it works
model.update({}, result[0])...
{ Okay: 1, nModified: 1, n: 1 }
I’m not sure but it won’t be necessary
{multi: true}
in the arguments ? https://docs.mongodb.com/manual/reference/method/db.collection.update/#multi-parameter– Sergio
already tried model.update({}, list, { multi: true }), does not work.
– JBarbosa
I think it’s only good for equal changes for all documents
– JBarbosa
You want to update what? The
model
? If this list of your example is the new names for each document, you will need an update for each doc. Type:lista.forEach(function(item){ model.update({_id: item._id}, {nome: item.nome}).then(...); });
– sergiopereira
@sergiopereira works :), but it would be nice to have something from mongodb that already does this, can put as an answer.
– JBarbosa