1

I need plain javascript object instead of mongoose object.

Query

chatModel.find({'userId':userId},{
            "_id":0,"message":1,"type":1            
           }).sort({createdDateISO:-1})
          .lean().exec((err,result)=>{
      });

But I will get mongoose object when I remove the sort() I am getting the plain javascript object. How do i get the plain object with sort??

shamon shamsudeen
  • 5,466
  • 17
  • 64
  • 129

1 Answers1

0

Passing options (in this case return the raw js objects, not mongoose documents by passing lean.So you cant use lean with sort(only use with mongoose document)

ŞükSefHam
  • 167
  • 1
  • 10