0

I want to get latest inserted record which have same name using node.js

Here is my code:

gfs.db.collection("file").findOne({ filename:'Sample.txt'}, (err, file) => {
 console.log(file)
})

Here I'm finding file name with Sample.txt, In my db I have many docs,and 2 docs with same filename that is Sample.txt, When I use above function it's return Sample.txt of old inserted data instead of new one So I used sort still it's not working

This is sort code

 gfs.db.collection("files").findOne({ filename:'Sample.txt'}, { sort: { 'filename': -1 } }, (err, file) => { console.log(file)})

So after using this thing I'm getting details of old Sample.txt instead of new. Can some one please Help me on this.

Thanks

sss
  • 251
  • 5
  • 18

0 Answers0