Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-24832

Project array by text search predicate

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Querying, Text Search
    • Labels:
      None

      Description

      Suppose I create the following db/collection:

      > use articles
      > db.stores.insert( [ 
                   {_id : 1, arr : ['abc xyz', 'def']}, 
                   {_id : 2, arr : ['jadskf', 'ljh abc']}])
      > db.stores.createIndex({"arr" : "text"})
      

      I want to do text search over the arrays arr and obtain only the array elements that match the search.

      For instance,

      > db.stores.find({$text : {$search : "abc"}})
      { "_id" : 1, "arr" : [ "abc xyz", "def" ] }
      { "_id" : 2, "arr" : [ "jadskf", "ljh abc" ] }
      

      Ideally I'd like to only obtain the first element of the arr in the first document: abc xyz and only the second element of the arr in the second document: ljh abc, and also the _id of the matched documents.

      Note that what I want is not a simple projection of the arr element, but of the elements of the arr where the match occurred.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated: