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

weird $sort behavior

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.9, 2.6.0-rc2
    • Component/s: Querying
    • Labels:
      None
    • ALL

      >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 } } ] }
      

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

              Created:
              Updated:
              Resolved: