![]() Example Get your own Node.js Server Sort the result alphabetically by name: var MongoClient require ('mongodb'). ![]() The sort () method takes one parameter, an object defining the sorting order. The methods listed above are synchronous, that is they will block until the result is returned. Node.js MongoDB Sort Previous Next Sort the Result Use the sort () method to sort the result in ascending or descending order. Just as I summarised the find section above, tools such as lodash can do far more, but in most cases, JavaScript’s built-in filter method will be all you need. If you want to follow along, this is the example data I will be using.ĭata.json Īs you can see, filter returns an array and it contains both records with the name field that contains the Doe Filter Summary Let us try to access a MongoDB database with Node.js.
0 Comments
Leave a Reply. |