Consider the following mongoose model:
const UserSchema = Schema({
//_id: ObjectId,
//more fields,
blockedIds: [{
type: ObjectId,
ref: 'User'
}]
})
What would be the most optimal approach to retrieve all users who do not have their _id listed in the blockedIds array of a specific user?
One way to do this could be by executing two separate queries:
User.findById(id).then(user => {
return User.find({_id: {$nin: user.blockedIds}})
})
Is it feasible to utilize the aggregation framework and $facets in order to achieve this requirement with just one query?