Skip to content

Instantly share code, notes, and snippets.

@rturk
Created February 12, 2016 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rturk/f5ff8a16124365b8a113 to your computer and use it in GitHub Desktop.
Save rturk/f5ff8a16124365b8a113 to your computer and use it in GitHub Desktop.
Mongoose Virtual field async await
Schema.virtual('comments')
//Returns comment owned by this product
.get(
async obj => await Comment
.find({ 'owner': this._id, deleted: { $ne: true } })
.sort('-likesCount -date_modified')
.limit(6)
.exec()
);
@DanPen
Copy link

DanPen commented Jul 28, 2017

Thanks for sharing! Just what I need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment