Skip to content

Commit d63615e

Browse files
committed
JAVA-705: Use collection's default read preference and options for command helpers like mapReduce, aggregate, and collStats.
1 parent 0e1daca commit d63615e

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/main/com/mongodb/DBCollection.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
// Mongo
2222

23-
import org.bson.LazyBSONObject;
2423
import org.bson.LazyDBList;
2524
import org.bson.types.ObjectId;
2625

@@ -1149,9 +1148,9 @@ public List distinct( String key, ReadPreference readPrefs ){
11491148
* @return
11501149
* @throws MongoException
11511150
*/
1152-
public List distinct( String key , DBObject query ){
1153-
return distinct(key, query, getReadPreference());
1154-
}
1151+
public List distinct( String key , DBObject query ){
1152+
return distinct(key, query, getReadPreference());
1153+
}
11551154

11561155
/**
11571156
* find distinct values for a key
@@ -1172,7 +1171,7 @@ public List distinct( String key , DBObject query, ReadPreference readPrefs ){
11721171
res.throwOnError();
11731172
return (List)(res.get( "values" ));
11741173
}
1175-
1174+
11761175
/**
11771176
* performs a map reduce operation
11781177
* Runs the command in REPLACE output mode (saves to named collection)
@@ -1262,11 +1261,7 @@ public MapReduceOutput mapReduce( String map , String reduce , String outputTarg
12621261
public MapReduceOutput mapReduce( MapReduceCommand command ){
12631262
DBObject cmd = command.toDBObject();
12641263
// if type in inline, then query options like slaveOk is fine
1265-
CommandResult res = null;
1266-
if (command.getOutputType() == MapReduceCommand.OutputType.INLINE)
1267-
res = _db.command( cmd, getOptions(), command.getReadPreference() != null ? command.getReadPreference() : getReadPreference() );
1268-
else
1269-
res = _db.command( cmd );
1264+
CommandResult res = _db.command( cmd, getOptions(), command.getReadPreference() != null ? command.getReadPreference() : getReadPreference() );
12701265
res.throwOnError();
12711266
return new MapReduceOutput( this , cmd, res );
12721267
}
@@ -1282,7 +1277,7 @@ public MapReduceOutput mapReduce( MapReduceCommand command ){
12821277
public MapReduceOutput mapReduce( DBObject command ){
12831278
if ( command.get( "mapreduce" ) == null && command.get( "mapReduce" ) == null )
12841279
throw new IllegalArgumentException( "need mapreduce arg" );
1285-
CommandResult res = _db.command( command );
1280+
CommandResult res = _db.command( command, getOptions(), getReadPreference() );
12861281
res.throwOnError();
12871282
return new MapReduceOutput( this , command, res );
12881283
}
@@ -1309,7 +1304,7 @@ public AggregationOutput aggregate( DBObject firstOp, DBObject ... additionalOps
13091304
Collections.addAll(pipelineOps, additionalOps);
13101305
command.put( "pipeline", pipelineOps );
13111306

1312-
CommandResult res = _db.command( command );
1307+
CommandResult res = _db.command( command, getOptions(), getReadPreference() );
13131308
res.throwOnError();
13141309
return new AggregationOutput( command, res );
13151310
}
@@ -1360,7 +1355,7 @@ public void dropIndex( String name ){
13601355
* @throws MongoException
13611356
*/
13621357
public CommandResult getStats() {
1363-
return getDB().command(new BasicDBObject("collstats", getName()), getOptions());
1358+
return getDB().command(new BasicDBObject("collstats", getName()), getOptions(), getReadPreference());
13641359
}
13651360

13661361
/**

0 commit comments

Comments
 (0)