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

sort() sorts wrong when sorted string contains numbers

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.2.0
    • Component/s: None
    • Environment:
      OS X 10.8.2 (12C60) 64bit
      db version v2.2.0, pdfile version 4.5
      Thu Oct 18 14:40:04 git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
    • ALL

      Is this normal behavior or a bug?

      > db.test.insert({a:1})
      > db.test.insert({a:10})
      > db.test.insert({a:9})
      > db.test.insert({a:4})
      > db.test.insert({a:4})
      > db.test.insert({a:50}) 
      > 
      > db.test.find().sort({a:1})
      { "_id" : ObjectId("507ff0d917258e582f785be1"), "a" : 1 }
      { "_id" : ObjectId("507ff0e117258e582f785be4"), "a" : 4 }
      { "_id" : ObjectId("507ff0e217258e582f785be5"), "a" : 4 }
      { "_id" : ObjectId("507ff0df17258e582f785be3"), "a" : 9 }
      { "_id" : ObjectId("507ff0dd17258e582f785be2"), "a" : 10 }
      { "_id" : ObjectId("507ff0e517258e582f785be6"), "a" : 50 }
      > db.test.remove()
      > 
      > db.test.insert({a:'a1'})
      > db.test.insert({a:'a10'})
      > db.test.insert({a:'a20'})
      > db.test.insert({a:'a4'})
      > db.test.insert({a:'a2'})
      > db.test.insert({a:'a4'})
      > db.test.insert({a:'a9'})
      > 
      > db.test.find().sort({a:1})
      { "_id" : ObjectId("507ff10117258e582f785be7"), "a" : "a1" }
      { "_id" : ObjectId("507ff10317258e582f785be8"), "a" : "a10" }
      { "_id" : ObjectId("507ff10b17258e582f785beb"), "a" : "a2" }
      { "_id" : ObjectId("507ff10517258e582f785be9"), "a" : "a20" }
      { "_id" : ObjectId("507ff10817258e582f785bea"), "a" : "a4" }
      { "_id" : ObjectId("507ff11317258e582f785bec"), "a" : "a4" }
      { "_id" : ObjectId("507ff11517258e582f785bed"), "a" : "a9" }
      

      I thought it will sort a1, a2, a4,... , a10, a20

            Assignee:
            Unassigned Unassigned
            Reporter:
            cablecart Manuel Baesler
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: