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

Can't canonicalize query: BadValue bad sort specification

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.0
    • Component/s: Querying
    • None
    • Major Change
    • ALL
    • Hide

      Run in the Mongo shell:

      db.runCommand({ findandmodify: "test", query: { _lock: { $lte: 9999999999999 } }, update: { }, sort: [ [ "_lock", 1 ] ] })
      

      Expected: Returned updated document.

      Actual: Returned an error.

      Show
      Run in the Mongo shell: db.runCommand({ findandmodify: "test" , query: { _lock: { $lte: 9999999999999 } }, update: { }, sort: [ [ "_lock" , 1 ] ] }) Expected: Returned updated document. Actual: Returned an error.

      After upgrading from 2.4 to 2.6.0 our find_and_modify commands which use sorting started failing with the above error.

      PyMongo generates the following command for find_and_modify with sorting:

      { findandmodify: "test", query: { _lock: { $lte: 9999999999999 } }, update: { $set: { _lock: 1 } }, sort: [ [ "_lock", 1 ] ] }
      

      I tested it with 2.4 and it works fine, but on 2.6.0 it fails with the error (with the latest PyMongo 2.7):

      > db.runCommand({ findandmodify: "test", query: { _lock: { $lte: 9999999999999 } }, update: { }, sort: [ [ "_lock", 1 ] ] })
      {
      	"errmsg" : "exception: nextSafe(): { $err: \"Can't canonicalize query: BadValue bad sort specification\", code: 17287 }",
      	"code" : 13106,
      	"ok" : 0
      }
      

      Looks like MongoDB has stopped respecting "sort: [ [ "_lock", 1 ] ]" syntax.

      Is this a bug or expected change? This effectively breaks PyMongo's find_and_modify with sort functionality.

            Assignee:
            Unassigned Unassigned
            Reporter:
            r0mant Roman Tkachenko
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: