Mongodb atlas: how to apply limit and sort using Atlas console's filter option

1.2k Views Asked by At

I am using Mongodb Atlas and need to get the last 10 records. For which, have to apply a filter having sort and limit options. In mongo shell, we do it in this way:

db.category.find().sort( { name: 1 } ).limit( 5 )

or

db.category.find().limit( 5 ).sort( { name: 1 } )

How Mongodb Atlas console's filter option can be used for having the desired result? I didn't find any documentation for this, is it documented somewhere that how filter option can be used?

1

There are 1 best solutions below

0
On

Two possible solutions are available on the MongoDB atlas for your problem

1. Connect your MongoDB atlas two command line. On the home page of the atlas, click Connect, then Connect to Mongo Shell so there you get the connection string to connect with the command line and fire query over there and get the required result.

2. Create aggregate function on collection.

Click on the collection, then you will find the option of aggregation so click on Aggregation then 1st select $sort condition, then select $limit condition and get the required data.

Please refer to uploaded image: sample sort and limit condition on specific collection