@@ -80,20 +80,21 @@ public final DBCollection getCollection( String name ){
80
80
/**
81
81
* Creates a collection with a given name and options.
82
82
* If the collection does not exist, a new collection is created.
83
+ * Note that if the options parameter is null, the creation will be deferred to when the collection is written to.
83
84
* Possible options:
84
85
* <dl>
85
86
* <dt>capped</dt><dd><i>boolean</i>: if the collection is capped</dd>
86
87
* <dt>size</dt><dd><i>int</i>: collection size (in bytes)</dd>
87
88
* <dt>max</dt><dd><i>int</i>: max number of documents</dd>
88
89
* </dl>
89
90
* @param name the name of the collection to return
90
- * @param o options
91
+ * @param options options
91
92
* @return the collection
92
93
*/
93
- public final DBCollection createCollection ( String name , DBObject o ){
94
- if ( o != null ){
94
+ public final DBCollection createCollection ( String name , DBObject options ){
95
+ if ( options != null ){
95
96
DBObject createCmd = new BasicDBObject ("create" , name );
96
- createCmd .putAll (o );
97
+ createCmd .putAll (options );
97
98
CommandResult result = command (createCmd );
98
99
result .throwOnError ();
99
100
}
@@ -173,6 +174,20 @@ public CommandResult command( String cmd )
173
174
return command ( new BasicDBObject ( cmd , Boolean .TRUE ) );
174
175
}
175
176
177
+ /**
178
+ * Executes a database command.
179
+ * This method constructs a simple dbobject and calls {@link DB#command(com.mongodb.DBObject, int) }
180
+ * @see <a href="http://mongodb.onconfluence.com/display/DOCS/List+of+Database+Commands">List of Commands</a>
181
+ * @param cmd command to execute
182
+ * @param options query options to use
183
+ * @return result of command from the database
184
+ * @throws MongoException
185
+ */
186
+ public CommandResult command ( String cmd , int options )
187
+ throws MongoException {
188
+ return command ( new BasicDBObject ( cmd , Boolean .TRUE ), options );
189
+ }
190
+
176
191
/**
177
192
* evaluates a function on the database.
178
193
* This is useful if you need to touch a lot of data lightly, in which case network transfer could be a bottleneck.
@@ -495,13 +510,13 @@ static DBObject _authCommand( String nonce , String username , byte[] hash ){
495
510
}
496
511
497
512
private CommandResult _doauth ( String username , byte [] hash ){
498
- CommandResult res = command (new BasicDBObject ("getnonce" , 1 ));
513
+ CommandResult res = command (new BasicDBObject ("getnonce" , 1 ), getOptions () );
499
514
if ( ! res .ok () ){
500
515
throw new MongoException (res );
501
516
}
502
517
503
518
DBObject cmd = _authCommand ( res .getString ( "nonce" ) , username , hash );
504
- return command (cmd );
519
+ return command (cmd , getOptions () );
505
520
}
506
521
507
522
/**
0 commit comments