How to write orderby clause using MongoDB java drivers?

Today we will write a sample program using MongoDB java driver to sort a collection.

Assume that we have a collection like this.

Sorting or ordering by a particular column is really simple using the console, The sort function takes column(s) name and order in which the sorting needs to be done. (-1 == descending and 1 == ascending)

Sample program assume that the MongoDB installed in your local machine and running on default port. Please change the host and port if your MongoDB server is running in a different environment.

Run the program and see the console output.

The collections sorted or ordered by the key “Total Score”

One thought on “How to write orderby clause using MongoDB java drivers?

Leave a comment

Your email address will not be published. Required fields are marked *