mongoose-paginate icon indicating copy to clipboard operation
mongoose-paginate copied to clipboard

Support for virtual field

Open vailancio opened this issue 6 years ago • 3 comments

I have a virtual field on my modal but it does not show up after I paginate.

vailancio avatar Mar 21 '18 16:03 vailancio

Maybe that's not super efficient but you can always do this to get virtuals. Keep in mind you have to set virtuals: true in the Schema toObject option.

Schema.paginate({}, { limit: 5 }).then(result => {
    for (let index in result.docs) {
      result.docs[index] = result.docs[index].toObject();
    }
    return result;
});

tzaborski avatar Dec 28 '18 17:12 tzaborski

in yours schema definition, set options like :

 {
    toJSON: { virtuals: true }
  }

leandrorazevedo avatar Nov 28 '19 20:11 leandrorazevedo

in yours schema definition, set options like :

 {
    toJSON: { virtuals: true }
  }

Thank you bro, saved my life :)

smallbzleads avatar Sep 18 '21 10:09 smallbzleads