XMLWordPrintable

    Details

    • Type: Question
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 1.6.4
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      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 }

      ]
      ]
      }
      }

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: