I have the following query which pulls an id
from two arrays (requests and followers) in the document:
User.updateOne(
{ _id: otherUserId },
{ $pull: { requests: userId, followers: userId } }
)
I want to modify this query by using a condition stating if the userId
is in requests
array, then pull from requests
but don’t update the followers array. If the id
is not in requests
then pull from followers
. Currently, both fields are updated regardless. Any way to accomplish this using one query? Thanks