|
20 | 20 |
|
21 | 21 | import java.util.*;
|
22 | 22 |
|
23 |
| -import com.mongodb.DBApiLayer.MyCollection; |
24 | 23 | import com.mongodb.DBApiLayer.Result;
|
25 | 24 |
|
26 | 25 |
|
@@ -82,6 +81,7 @@ public DBCursor copy() {
|
82 | 81 | DBCursor c = new DBCursor(_collection, _query, _keysWanted);
|
83 | 82 | c._orderBy = _orderBy;
|
84 | 83 | c._hint = _hint;
|
| 84 | + c._hintDBObj = _hintDBObj; |
85 | 85 | c._limit = _limit;
|
86 | 86 | c._skip = _skip;
|
87 | 87 | c._options = _options;
|
@@ -137,17 +137,14 @@ public DBCursor addSpecial( String name , Object o ){
|
137 | 137 |
|
138 | 138 | /**
|
139 | 139 | * Informs the database of indexed fields of the collection in order to improve performance.
|
140 |
| - * @param indexKeys a <code>DBObject</code> with index names as keys |
| 140 | + * @param indexKeys a <code>DBObject</code> with fields and direction |
141 | 141 | * @return same DBCursor for chaining operations
|
142 | 142 | */
|
143 | 143 | public DBCursor hint( DBObject indexKeys ){
|
144 | 144 | if ( _it != null )
|
145 | 145 | throw new IllegalStateException( "can't hint after executing query" );
|
146 | 146 |
|
147 |
| - if ( indexKeys == null ) |
148 |
| - _hint = null; |
149 |
| - else |
150 |
| - _hint = DBCollection.genIndexName( indexKeys ); |
| 147 | + _hintDBObj = indexKeys; |
151 | 148 | return this;
|
152 | 149 | }
|
153 | 150 |
|
@@ -343,7 +340,10 @@ private void _check()
|
343 | 340 |
|
344 | 341 | _addToQueryObject( foo , "query" , _query , true );
|
345 | 342 | _addToQueryObject( foo , "orderby" , _orderBy , false );
|
346 |
| - _addToQueryObject( foo , "$hint" , _hint ); |
| 343 | + if(_hint != null) |
| 344 | + _addToQueryObject( foo , "$hint" , _hint ); |
| 345 | + if(_hintDBObj != null) |
| 346 | + _addToQueryObject( foo , "$hint" , _hintDBObj); |
347 | 347 |
|
348 | 348 | if ( _explain )
|
349 | 349 | foo.put( "$explain" , true );
|
@@ -392,7 +392,7 @@ boolean hasSpecialQueryFields(){
|
392 | 392 | if ( _orderBy != null && _orderBy.keySet().size() > 0 )
|
393 | 393 | return true;
|
394 | 394 |
|
395 |
| - if ( _hint != null || _snapshot ) |
| 395 | + if ( _hint != null || _hintDBObj != null || _snapshot ) |
396 | 396 | return true;
|
397 | 397 |
|
398 | 398 | return _explain;
|
@@ -700,6 +700,7 @@ public String toString() {
|
700 | 700 |
|
701 | 701 | private DBObject _orderBy = null;
|
702 | 702 | private String _hint = null;
|
| 703 | + private DBObject _hintDBObj = null; |
703 | 704 | private boolean _explain = false;
|
704 | 705 | private int _limit = 0;
|
705 | 706 | private int _batchSize = 0;
|
|
0 commit comments