• Type: Icon: Question Question
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.6.4
    • Component/s: None
    • None

      From the mailing list:
      db.test.insert(

      { parts : ["part1", "part2", "part3", "part4"], priority : 2 }

      );
      db.test.insert(

      { parts : ["part4", "part5", "part6"], priority : 5 }

      );
      db.test.ensureIndex(

      { parts : 1, priority : -1 }

      )

      // Uses an index
      db.test.find({$or : [{ parts :

      { $all : ["part1", "part2"] }

      },

      { parts : "part4" }

      ]}).explain()

      // Does not use an index
      db.test.find({$or : [{ parts :

      { $all : ["part1", "part2"] }

      },

      { parts : "part4" }

      ]}).sort(

      { priority : -1 }

      ).explain()

      // Uses the index, but doesn't produce expected explain output
      db.test.find({$or : [{ parts :

      { $all : ["part1", "part2"] }

      },

      { parts : "part4" }

      ]}).sort(

      { priority : -1 }

      ).hint(

      {parts: 1, priority: -1}

      ).explain()

      // Here's the output (it's NOT in the form of the typical $or-like explain plan)
      {
      "cursor" : "BtreeCursor parts_1_priority_-1",
      "nscanned" : 7,
      "nscannedObjects" : 7,
      "n" : 2,
      "scanAndOrder" : true,
      "millis" : 0,
      "indexBounds" : {
      "parts" : [
      [

      { "$minElement" : 1 }

      ,

      { "$maxElement" : 1 }

      ]
      ],
      "priority" : [
      [

      { "$maxElement" : 1 }

      ,

      { "$minElement" : 1 }

      ]
      ]
      }
      }

            Assignee:
            aaron Aaron Staple
            Reporter:
            kbanker Kyle Banker
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: