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

1

7

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?

Nerte answered 7/10, 2020 at 6:36 Comment(2)
What atlas ui are you referring to?Canfield
I am using Mongodb atlas console and data explorer to filter. @D.SMNerte
S
1

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

Shiloh answered 2/1, 2023 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.