❔ Is there a way to improve this code Performance ?
have a collection of items that have
I want to do the following:
Here I am making 4 calls to the database (3 finds and 1 update). Is there some way to write this more efficiently ?
_id and serialNumbers (an array) fields (and other fields as well but irrelevant for the question).I want to do the following:
- Check that the
newSerialNumberis not used in any document. - Filter to find out the item with the given
id, lets name itItemX - Get all the items that have the same serialNumbers as
ItemX. Let's name themItemsWithSameSerialNumbersAsItemX - For each one of the
ItemsWithSameSerialNumbersAsItemX, push thenewSerialNumber
Here I am making 4 calls to the database (3 finds and 1 update). Is there some way to write this more efficiently ?