-
Type: Bug
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
None
-
ALL
When a $natural hint is parsed, the directional argument is ignored. This can cause an unexpected result, because hinting $natural in reverse direction does a $natural query in forward direction. (Reverse natural order can be specified using sort rather than hint.) The argument passed to hint is generally used identify an index, not the direction the index should be traversed (which can be specified by sort). I think
{ $natural:-1 }should be treated as an invalid hint, as the schema for an unindexed scan is
{ $natural:1 }(different).
c = db.c; c.drop(); c.save( { a:0 } ); c.save( { a:1 } ); function checkResultSet( expected, actual ) { assert.eq( expected.length, actual.length ); for( i = 0; i < expected.length; ++i ) { assert.eq( expected[ i ], actual[ i ].a ); } } checkResultSet( [ 0, 1 ], c.find().sort( { $natural:1 } ).toArray() ); checkResultSet( [ 0, 1 ], c.find().hint( { $natural:1 } ).toArray() ); checkResultSet( [ 1, 0 ], c.find().sort( { $natural:-1 } ).toArray() ); // This returns results as $natural:1, should uassert instead (I think). checkResultSet( [ 1, 0 ], c.find().hint( { $natural:-1 } ).toArray() );
- is duplicated by
-
SERVER-14459 Query with hint({$natural: -1}) returns documents in a forward order
- Closed
- is related to
-
SERVER-8564 Clean up unneeded code for $natural hint overriding $natural sort
- Backlog