how to use mongodb aggregate and retrieve entire documents

后端 未结 5 2069
猫巷女王i
猫巷女王i 2021-01-11 10:53

I am seriously baffled by mongodb\'s aggregate function. All I want is to find the newest document in my collection. Let\'s say each record has a field \"created\"



        
5条回答
  •  [愿得一人]
    2021-01-11 11:32

    You should be using db.collection.find() rather than db.collection.aggregate():

    db.collection.find().sort({"created":-1}).limit(1)
    

提交回复
热议问题