Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-137

Project and sort by $meta.

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Component/s: None

      MongoDB 2.6 includes a $text query operator. There's a new projection syntax for including each result's relevance in the output. There's also a new syntax for sorting by relevance descending:

      > db.test.createIndex({s: 'text'})
      > db.test.insert({s: 'spam'})
      > db.test.insert({s: 'spam eggs and spam'})
      > db.test.insert({s: 'sausage and eggs'})
      >
      > db.test.find(
      ...   // query
      ...   {$text: {$search: 'spam'}},
      ...   // new projection syntax
      ...   {_id: false, s: true, score: {$meta: 'textScore'}}
      ... ).sort(
      ...   // new sort syntax
      ...  {score: {$meta: 'textScore'}}
      )
      { "s" : "spam eggs and spam", "score" : 1.25 }
      { "s" : "spam", "score" : 1.1 }
      

      Drivers probably already support the new projection syntax, since it's a similar structure to the $elemMatch projection operator.

      If a driver has been validating that the value portion of a sort specifier is 1, -1, or a string, it should now also allow a subdocument as the value, possibly with $-prefixed field names.

            Assignee:
            barrie Barrie Segal
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: