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

weird $sort behavior

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Works as Designed
    • 2.4.9, 2.6.0-rc2
    • None
    • Querying
    • None
    • ALL

    Description

      >db.test.drop()
      >db.test.insert([{a:[{b:{c:3}}, 1]}, {a:[{b:{c:5}},1]}, {a:[{b:{c:4}},1]}])
      >db.test.find().sort({'a.b.c':1})
      { "_id" : ObjectId("5339c1f58b8794d6f2676019"), "a" : [ { "b" : { "c" : 3 } }, 1 ] }
      { "_id" : ObjectId("5339c1f58b8794d6f267601a"), "a" : [ { "b" : { "c" : 5 } }, 1 ] }
      { "_id" : ObjectId("5339c1f58b8794d6f267601b"), "a" : [ { "b" : { "c" : 4 } }, 1 ] }

      should the {a:[{b:{c:5}},1]} be the last doc? They do if they don't have the 1 in the array.

      >db.test.drop()
      >db.test.insert([{a:[{b:{c:3}}]}, {a:[{b:{c:5}}]}, {a:[{b:{c:4}}]}])
      >db.test.find().sort({'a.b.c':1})
      { "_id" : ObjectId("5339d2a26d764829de404bec"), "a" : [ { "b" : { "c" : 3 } } ] }
      { "_id" : ObjectId("5339d2a26d764829de404bee"), "a" : [ { "b" : { "c" : 4 } } ] }
      { "_id" : ObjectId("5339d2a26d764829de404bed"), "a" : [ { "b" : { "c" : 5 } } ] }

      Attachments

        Issue Links

          Activity

            People

              david.storch@mongodb.com David Storch
              sduan Steve Duan
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: