$text behaves differently on non-existent vs empty collection

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.6.10, 3.0.5
    • Component/s: Querying, Text Search
    • None
    • Query
    • Fully Compatible
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Both an empty collection and a non-existent collection have no text index. Therefore, I expect their behaviour with respect to $text to be the same. However, the empty collection case returns an error, whereas on a non-existent collection the query apparently "succeeds" (even though it's probably short-circuiting somewhere).

      > db.a.drop()
      false
      > db.createCollection("a")
      { "ok" : 1 }
      > db.a.find( { "$text": { "$search": "foobar" } } )
      Error: error: {
              "$err" : "Unable to execute query: error processing query: ns=test.a limit=0 skip=0\nTree: TEXT : query=foobar, language=, tag=NULL\nSort: {}\nProj: {}\n planner returned error: need exactly one text index for $text query",
              "code" : 17007
      }
      > db.a.drop()
      true
      > db.a.find( { "$text": { "$search": "foobar" } } )
      > 
      

      In 3.0.5 the explain plan is:

      > db.a.find( { "$text": { "$search": "foobar" } } ).explain(true)
      {
              "queryPlanner" : {
                      "plannerVersion" : 1,
                      "namespace" : "test.a",
                      "indexFilterSet" : false,
                      "parsedQuery" : {
                              "$text" : {
                                      "$search" : "foobar",
                                      "$language" : ""
                              }
                      },
                      "winningPlan" : {
                              "stage" : "EOF"
                      },
                      "rejectedPlans" : [ ]
              },
              "executionStats" : {
                      "executionSuccess" : true,
                      "nReturned" : 0,
                      "executionTimeMillis" : 0,
                      "totalKeysExamined" : 0,
                      "totalDocsExamined" : 0,
                      "executionStages" : {
                              "stage" : "EOF",
                              "nReturned" : 0,
                              "executionTimeMillisEstimate" : 0,
                              "works" : 1,
                              "advanced" : 0,
                              "needTime" : 0,
                              "needFetch" : 0,
                              "saveState" : 0,
                              "restoreState" : 0,
                              "isEOF" : 1,
                              "invalidates" : 0
                      },
                      "allPlansExecution" : [ ]
              },
              "serverInfo" : {
                      "host" : "genique",
                      "port" : 23249,
                      "version" : "3.0.5",
                      "gitVersion" : "8bc4ae20708dbb493cb09338d9e7be6698e4a3a3"
              },
              "ok" : 1
      }
      

      In 2.6.10 it is:

      > db.a.find( { "$text": { "$search": "foobar" } } ).explain(true)
      {
              "cursor" : "BasicCursor",
              "isMultiKey" : false,
              "n" : 0,
              "nscannedObjects" : 0,
              "nscanned" : 0,
              "nscannedObjectsAllPlans" : 0,
              "nscannedAllPlans" : 0,
              "scanAndOrder" : false,
              "indexOnly" : false,
              "nYields" : 0,
              "nChunkSkips" : 0,
              "millis" : 0,
              "allPlans" : [
                      {
                              "cursor" : "BasicCursor",
                              "n" : 0,
                              "nscannedObjects" : 0,
                              "nscanned" : 0
                      }
              ],
              "server" : "genique:27017"
      

            Assignee:
            Backlog - Query Team (Inactive)
            Reporter:
            Kevin Pulo
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: