Answer the question
In order to leave comments, you need to log in
How to update two fields of different structure in Mongo in one request?
Good evening.
There is a table that stores documents of three different types, which have slightly different field structures. It is necessary to delete the transferred ID from there. So far I've written three separate queries, but is it possible to combine them into one?
await Documents.update({
'payload.manualAssignments.userId': _id,
}, {
'$pull': {
// Это массив документов, у которого удаляем документ по его полю
'payload.manualAssignments': { userId: _id },
}
}, {
multi: true,
});
await Documents.update({
'payload.autoAssignments.userId': _id,
}, {
'$pull': {
// А это просто массив айдишников, у которого просто удаляем значение
'payload.autoAssignments.userId': _id,
}
}, {
multi: true,
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question