suppose we have a User model that contains an array of other User objects.
let UserSchema = mongoose.Schema({
followers: [{
type: mongoose.Schema.ObjectId,
ref: 'User',
}]
})
I need a count of this objectIds. the first solution is to get length of followers.
req.user.followers.length
but I think it's not relevant to get all the followers that contains many of objectIds. and in my query i dont need all of this objectIds. I tried to use virtuals but in virtuals I have many unnecessary pieces of stuff.I'm looking for the best and uncosted way for this type of situations.