I want to get First top 10 result in MongoDb Query
For that I tried something like this
return _users.Collection.FindAll().Limit(10).ToList();
But this is not working then I tried following thing according to most of resources, but this one also not working
return _users.Collection.Aggregate([{ "$limit": 10 }]).ToList();
On the MongoDB shell you can do: db. collectionName.
To skip records in MongoDB, use skip(). With that, to display only a specific number of records, use limit().
Use the $first operator to get the first record of the group, which will also be the oldest. Use the $last operator to get the last record in the group, which will also be the newest. To get the entire record use the $$ROOT system variable.
Try
return _users.Collection.Find(x => true).Limit(10).ToList();
Instead of FindAll()
find({})
will find all the documents and limit()
will filter your results.
return _users.Collection.find({}).limit(10).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With