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?

2
  • What atlas ui are you referring to? Commented Oct 7, 2020 at 21:30
  • I am using Mongodb atlas console and data explorer to filter. @D.SM Commented Oct 8, 2020 at 9:49

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.