Returning inner array elements from multiple document in sorted form

后端 未结 2 545
谎友^
谎友^ 2020-12-21 11:18

hyy there, my collection goes like this and I am trying to get all comments list of particular blog_id in sorted order of date.

    [
{
    \"_id\" : ObjectI         


        
2条回答
  •  一向
    一向 (楼主)
    2020-12-21 11:50

    to do this, you can use method findById then sort your comments with method sort of mongoose.

    With a example :

    Blog.find({blog_id : YOUR_BLOG_ID}, 'comments')
    .sort('dt')
    .exec(function(err, docs){
     console.log(docs); // do whatever you want with your docs
    });
    

    Something like that should do the job.

提交回复
热议问题