File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -514,6 +514,26 @@ void _applyMongoOptions() {
514
514
setWriteConcern ( _options .getWriteConcern () );
515
515
}
516
516
517
+ /**
518
+ * Gets the maximum size for a BSON object supported by the current master server.
519
+ * Note that this method may make a request to the server to obtain the size.
520
+ * @throws MongoException
521
+ * @return the size supported, or 0 if it cannot be determined.
522
+ */
523
+ public int getMaxBsonObjectSize () {
524
+ int size = 0 ;
525
+ if (_connector .getReplicaSetStatus () != null )
526
+ size = _connector .getReplicaSetStatus ().getMaxBsonObjectSize ();
527
+ if (size == 0 ) {
528
+ // need to fetch size
529
+ DB db = getDB ("admin" );
530
+ CommandResult res = db .command ("isMaster" );
531
+ if (res .containsField ("maxBsonObjectSize" ))
532
+ size = ((Integer )res .get ( "maxBsonObjectSize" )).intValue ();
533
+ }
534
+ return size ;
535
+ }
536
+
517
537
final ServerAddress _addr ;
518
538
final List <ServerAddress > _addrs ;
519
539
final MongoOptions _options ;
Original file line number Diff line number Diff line change @@ -169,6 +169,10 @@ synchronized void update(Set<Node> seenNodes){
169
169
seenNodes .add (node );
170
170
}
171
171
}
172
+
173
+ if (_isMaster && res .containsField ("maxBsonObjectSize" ))
174
+ _maxBsonObjectSize = ((Integer )res .get ( "maxBsonObjectSize" )).intValue ();
175
+
172
176
}
173
177
catch ( MongoException e ){
174
178
Throwable root = e ;
@@ -388,11 +392,15 @@ void close(){
388
392
_closed = true ;
389
393
}
390
394
395
+ public int getMaxBsonObjectSize () {
396
+ return _maxBsonObjectSize ;
397
+ }
391
398
392
399
final List <Node > _all ;
393
400
Updater _updater ;
394
401
Mongo _mongo ;
395
402
String _setName = null ; // null until init
403
+ int _maxBsonObjectSize = 0 ;
396
404
Logger _logger = _rootLogger ; // will get changed to use set name once its found
397
405
398
406
String _lastPrimarySignal ;
You can’t perform that action at this time.
0 commit comments