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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • 2.2.6, 2.5.3
    • None
    • 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

    Description

      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
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jlee Jeff lee
              Votes:
              4 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: