Sorting, Indexing & Searching
Sorting Records
MongoDB provides the sort()
method to sort the documents in a collection based on one or more fields. The method accepts an object specifying the fields to sort on and the sort order (ascending or descending).
Creating and Deleting Text Indexes
MongoDB supports text indexes to perform text searches on string content. Text indexes can include any field whose value is a string or an array of string elements.
To create a text index:
To delete a text index:
Text Search on a Collection
Once you've created a text index, you can perform text searches using the $text
operator in the query.
Last updated
Was this helpful?