Mongoose Select Populated Data’s Size


This Content is from Stack Overflow. Question asked by Ömer Faruk Demirel

In my blog model;

user: {
    type: mongoose.Types.ObjectId,
    ref: 'users',
    required: true,

And this is my user model;

follower: [
      type: mongoose.Types.ObjectId,
      ref: 'users'

So I’m gettting data like this;

const Post = await Blog.findOne({slug: post}).populate({
      path: 'user',
      select: 'name image count(follower)'

Of course count(follower) not working. I want to get followers count, how can I do that?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?