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

Sorting doesn't work if sort key excluded in projection with a sharded collections

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.6, 2.5.3
    • Component/s: Querying, Sharding
    • ALL
    • Hide

      1. Create a sharded cluster - 1 shard
      2. Add a document to a collection. Does not require that the collection be sharded
      3. Run a query against the collection, excluding the key in the projection while attempting to sort by the same key

      Show
      1. Create a sharded cluster - 1 shard 2. Add a document to a collection. Does not require that the collection be sharded 3. Run a query against the collection, excluding the key in the projection while attempting to sort by the same key

      Hi,

      It looks like there was a behavior change between 2.0 and 2.2 that results in an error 13431 if you attempt to sort by a key that has been explicitly excluded in a projection when running a query via a mongos.

      I was just wondering if this is expected behavior.

      mongos> db.version()
      2.0.9
      mongos> db.foo.save({id:3, value:'c'})
      mongos> db.foo.save({id:2, value:'b'})
      mongos> db.foo.save({id:1, value:'a'})
      mongos> db.foo.find({},{id:0}).sort({id:1})
      { "_id" : ObjectId("523bd35dff9a7c468936efba"), "value" : "a" }
      { "_id" : ObjectId("523bd358ff9a7c468936efb9"), "value" : "b" }
      { "_id" : ObjectId("523bd352ff9a7c468936efb8"), "value" : "c" }
      
      mongos> db.version()
      2.2.6
      mongos> db.foo.find({},{id:0}).sort({id:1})
      error: {
              "$err" : "have to have sort key in projection and removing it",
              "code" : 13431
      }
      

        1. server10831.js
          0.4 kB
          David Storch

            Assignee:
            Unassigned Unassigned
            Reporter:
            jlee Jeff lee
            Votes:
            4 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: