File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,6 +62,25 @@ public static boolean serverIsAtLeastVersion(double version) {
6262 return Double .parseDouble (serverVersion .substring (0 , 3 )) >= version ;
6363 }
6464
65+ public static boolean isStandalone () {
66+ return !isReplicaSet () && !isSharded ();
67+ }
68+
69+ public static boolean isSharded () {
70+ CommandResult isMasterResult = runIsMaster ();
71+ Object msg = isMasterResult .get ("msg" );
72+ return msg != null && msg .equals ("isdbgrid" );
73+ }
74+
75+ public static boolean isReplicaSet () {
76+ return runIsMaster ().get ("setName" ) != null ;
77+ }
78+
79+ private static CommandResult runIsMaster () {
80+ // Check to see if this is a replica set... if not, get out of here.
81+ return getMongoClient ().getDB ("admin" ).command (new BasicDBObject ("ismaster" , 1 ));
82+ }
83+
6584 static class ShutdownHook extends Thread {
6685 @ Override
6786 public void run () {
You can’t perform that action at this time.
0 commit comments