MongoDB Documentation, Release 3.0.4 Return Results Sorted by Text Search Score Match on Text Score Specify a Language for Text Search 8.3.5 Indexing Strategies To sort by the text search score, include a $meta expression in the $sort stage. The following example matches on either the term cake or tea , sorts by the textScore in descending order, and returns only the title field in the results set. The specified metadata determines the sort order. For example, the "textScore" metadata sorts in descending order. See $meta for more information on metadata as well as an example of overriding the default sort order of the metadata. The "textScore" metadata is available for projections, sorts, and conditions subsequent the $match stage that includes the $text operation. The following example matches on either the term cake or tea , projects the title and the score fields, and then returns only those documents with a score greater than 1.0 . The following aggregation searches in spanish for documents that contain the term saber but not the term claro in the $match stage and calculates the total views for the matching documents in the $group stage. The best indexes for your application must take a number of factors into account, including the kinds of queries you expect, the ratio of reads to writes, and the amount of free memory on your system. When developing your indexing strategy you should have a deep understanding of your application’s queries. Before you build indexes, map out the types of queries you will run so that you can build indexes that reference those fields. 546 Chapter 8. Indexes db.articles.aggregate( [ { $match: { $text: { $search: "cake tea" } } }, { $sort: { score: { $meta: "textScore" } } }, { $project: { title: 1, _id: 0 } } ] ) db.articles.aggregate( [ { $match: { $text: { $search: "cake tea" } } }, { $project: { title: 1, _id: 0, score: { $meta: "textScore" } } }, { $match: { score: { $gt: 1.0 } } } ] ) db.articles.aggregate( [ { $match: { $text: { $search: "saber -claro", $language: "es" } } }, { $group: { _id: null , views: { $sum: "$views" } } } ] )