J
J
jspie2017-04-21 17:11:57
JavaScript
jspie, 2017-04-21 17:11:57

How to change objects through array and id?

There is an iduser and an array of id objects. How can one intelligently change the del field in certain objects by id from the array to satisfy iduser? Do so?

arraylist.map(e=>{
 return Todo.update({ $and: [{idUser: iduser}, {iditem: e.id}], {del: '+'} })
})

Or does mongoose have a more adequate solution without using an array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2017-04-21
@jspie

Something like this:

Todo.update({
    idUser: iduser,
    iditem: {
        $in: arraylist
    }
}, { del: '+' }, { multi: true });

Use the $in operator and pass the entire array there, it will update all the id entries that will be in the arrayList, also set the multi - true option in order to update all documents.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question