Get the latest record from mongodb collection

前端 未结 8 2094
我寻月下人不归
我寻月下人不归 2020-11-29 17:40

I want to know the most recent record in a collection. How to do that?

Note: I know the following command line queries works:

1. db.test.find().sort(         


        
8条回答
  •  伪装坚强ぢ
    2020-11-29 18:36

    This is a rehash of the previous answer but it's more likely to work on different mongodb versions.

    db.collection.find().limit(1).sort({$natural:-1})
    

提交回复
热议问题