How can I limit data using aggregate functions using mongoDB?

Viewed 14

I'm trying to get the last data inserted in my collection using MongoDB. This is my code:

dht11.aggregate(
  [ 
    {
        $lookup:
        {
          from: "storage_rooms",
          localField: "node",
          foreignField: "name",
          as: "MainStorage"
        }
    },
      { $unwind: "$MainStorage"},
      { $match: {node: "Main Storage"} },
  
 
  ]
  ).sort({$natural:-1}).limit(1);
0 Answers
Related