Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JAVA-705: Use collection's default read preference and options for co…

…mmand helpers like mapReduce, aggregate, and collStats.
  • Loading branch information...
commit d63615edf9c8633d8c27a7922ec1f65bca2d55a4 1 parent 0e1daca
@jyemin jyemin authored
Showing with 8 additions and 13 deletions.
  1. +8 −13 src/main/com/mongodb/DBCollection.java
View
21 src/main/com/mongodb/DBCollection.java
@@ -20,7 +20,6 @@
// Mongo
-import org.bson.LazyBSONObject;
import org.bson.LazyDBList;
import org.bson.types.ObjectId;
@@ -1149,9 +1148,9 @@ public List distinct( String key, ReadPreference readPrefs ){
* @return
* @throws MongoException
*/
- public List distinct( String key , DBObject query ){
- return distinct(key, query, getReadPreference());
- }
+ public List distinct( String key , DBObject query ){
+ return distinct(key, query, getReadPreference());
+ }
/**
* find distinct values for a key
@@ -1172,7 +1171,7 @@ public List distinct( String key , DBObject query, ReadPreference readPrefs ){
res.throwOnError();
return (List)(res.get( "values" ));
}
-
+
/**
* performs a map reduce operation
* Runs the command in REPLACE output mode (saves to named collection)
@@ -1262,11 +1261,7 @@ public MapReduceOutput mapReduce( String map , String reduce , String outputTarg
public MapReduceOutput mapReduce( MapReduceCommand command ){
DBObject cmd = command.toDBObject();
// if type in inline, then query options like slaveOk is fine
- CommandResult res = null;
- if (command.getOutputType() == MapReduceCommand.OutputType.INLINE)
- res = _db.command( cmd, getOptions(), command.getReadPreference() != null ? command.getReadPreference() : getReadPreference() );
- else
- res = _db.command( cmd );
+ CommandResult res = _db.command( cmd, getOptions(), command.getReadPreference() != null ? command.getReadPreference() : getReadPreference() );
res.throwOnError();
return new MapReduceOutput( this , cmd, res );
}
@@ -1282,7 +1277,7 @@ public MapReduceOutput mapReduce( MapReduceCommand command ){
public MapReduceOutput mapReduce( DBObject command ){
if ( command.get( "mapreduce" ) == null && command.get( "mapReduce" ) == null )
throw new IllegalArgumentException( "need mapreduce arg" );
- CommandResult res = _db.command( command );
+ CommandResult res = _db.command( command, getOptions(), getReadPreference() );
res.throwOnError();
return new MapReduceOutput( this , command, res );
}
@@ -1309,7 +1304,7 @@ public AggregationOutput aggregate( DBObject firstOp, DBObject ... additionalOps
Collections.addAll(pipelineOps, additionalOps);
command.put( "pipeline", pipelineOps );
- CommandResult res = _db.command( command );
+ CommandResult res = _db.command( command, getOptions(), getReadPreference() );
res.throwOnError();
return new AggregationOutput( command, res );
}
@@ -1360,7 +1355,7 @@ public void dropIndex( String name ){
* @throws MongoException
*/
public CommandResult getStats() {
- return getDB().command(new BasicDBObject("collstats", getName()), getOptions());
+ return getDB().command(new BasicDBObject("collstats", getName()), getOptions(), getReadPreference());
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.