So i started using mongodb aggregate framework few days ago so i implemented a $limit and a $skip method to my project like this :
let content = await dataSources.WarehouseItem.aggregate([
{ $match: {} },
{ $limit: 2 },
{
$group: {
_id: "$productName",
quantity: { $first: "$quantity" },
},
},
]);
But this code instead of it returning 2 documents it returns only 1 but when i put 3 it returns 2 and when i put 4 it returns 3 and so on , and the skip method is also isn't working as expected , there is 4 documents inside of this db but it doesn't return 3 when i do this :
let content = await dataSources.WarehouseItem.aggregate([
{ $match: {} },
{ $skip: 1 },
{
$group: {
_id: "$productName",
quantity: { $last: "$quantity" },
},
},
]);
it returns the whole 4 documents