A
A
Alexey Nikolaev2021-05-04 18:33:42
MongoDB
Alexey Nikolaev, 2021-05-04 18:33:42

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,
});

I would be grateful for links to documentation \ kicks in the right direction.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question