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

Difference between querying to mongos and mongod

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.5
    • Component/s: Sharding
    • Labels:
      None
    • Environment:
      RHEL 5.8
    • ALL
    • Hide

      > c = db.test.find(

      {title: "shay"}

      ,

      {f:0}

      ).sort(

      {"f":1}

      )

      { "_id" : ObjectId("525be8c1513f4b195eaa8d00"), "title" : "shay" }

      mongos> c = db.test.find(

      {title: "shay"}

      ,

      {f:0}

      ).sort(

      {"f":1}

      )
      error: {
      "$err" : "have to have sort key in projection and removing it",
      "code" : 13431
      }

      Show
      > c = db.test.find( {title: "shay"} , {f:0} ).sort( {"f":1} ) { "_id" : ObjectId("525be8c1513f4b195eaa8d00"), "title" : "shay" } mongos> c = db.test.find( {title: "shay"} , {f:0} ).sort( {"f":1} ) error: { "$err" : "have to have sort key in projection and removing it", "code" : 13431 }

      We've encountered an error migrating to sharded environment.
      It appear there is a difference between querying mongod and mongos as shown below:
      > c = db.test.find(

      {title: "shay"}

      ,

      {f:0}

      ).sort(

      {"f":1}

      )

      { "_id" : ObjectId("525be8c1513f4b195eaa8d00"), "title" : "shay" }

      mongos> c = db.test.find(

      {title: "shay"}

      ,

      {f:0}

      ).sort(

      {"f":1}

      )
      error: {
      "$err" : "have to have sort key in projection and removing it",
      "code" : 13431
      }
      I understand (now) that it is not possible to exclude a field from a query and sort on it through mongos (that gets the documents without the fields and needs to sort upon them).
      However, as development was done a single mongod, we've encountered this error only now when deploying at scale. Now this requires changing our application code accordingly.
      One of the reasons we chose MongoDB was the "scale without affecting existing data or application code" paradigm. Therefore I believe the same behavior of mongos' must be enforced on the shards as well to allow that.
      Thanks
      Shay

            Assignee:
            Unassigned Unassigned
            Reporter:
            sasher@nds.com Shay Asher
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: