Server should reject array values for sort specification

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: 3.0.3
    • Component/s: Querying
    • Query
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Passing invalid syntax to sort() should trigger an error. For example

      find().sort([('_id', -1)])
      

      may return different results than

      find().sort({_id : 1})
      

      which can cause confusion.

      Original description

      I have a sharded cluster and the following queries give me different results:

      db.all_events.aggregate([{$match:{'session_id':'1389946222338', 'event_type': {'$in': PREV_EVENTS}, 'timestamp': {'$lte': ISODate("2014-01-17T08:16:49.963Z")}, _id:{$ne:ObjectId('555b4b1c6d5ba860366c78e2')}}}, {$sort:{timestamp:-1, _id:-1}}, {$limit:1}])
      
      db.all_events.find({'session_id':'1389946222338', 'event_type': {'$in': PREV_EVENTS}, 'timestamp': {'$lte': ISODate("2014-01-17T08:16:49.963Z")}, '_id': {'$ne': ObjectId('555b4b1c6d5ba860366c78e2')}}).sort([('timestamp', -1), ('_id', -1)]).limit(1)
      

      Only the aggregate gives the correct result. That something like this can happen is BAD.

              Assignee:
              Backlog - Query Team (Inactive)
              Reporter:
              Patrick Lauber
              Votes:
              0 Vote for this issue
              Watchers:
              12 Start watching this issue

                Created:
                Updated:
                Resolved: