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

Server should reject array values for sort specification

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

      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-server-query Backlog - Query Team (Inactive)
            Reporter:
            digi604 Patrick Lauber
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: