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.
- is duplicated by
-
SERVER-19294 $orderby meta operator allows an array, which it ignores
- Closed