本文整理汇总了Java中com.mongodb.CommandResult.getString方法的典型用法代码示例。如果您正苦于以下问题:Java CommandResult.getString方法的具体用法?Java CommandResult.getString怎么用?Java CommandResult.getString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.CommandResult
的用法示例。
在下文中一共展示了CommandResult.getString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: status
import com.mongodb.CommandResult; //导入方法依赖的package包/类
@Override
public List<DependencyStatus> status() {
//note failures are tested manually for now, if you make changes test
//things still work
//TODO TEST add tests exercising failures
final String version;
try {
final CommandResult bi = gfs.getDB().command("buildInfo");
version = bi.getString("version");
} catch (MongoException e) {
LoggerFactory.getLogger(getClass())
.error("Failed to connect to MongoDB", e);
return Arrays.asList(new DependencyStatus(false,
"Couldn't connect to MongoDB: " + e.getMessage(),
"GridFS", "Unknown"));
}
return Arrays.asList(
new DependencyStatus(true, "OK", "GridFS", version));
}
示例2: status
import com.mongodb.CommandResult; //导入方法依赖的package包/类
public List<DependencyStatus> status() {
//note failures are tested manually for now, if you make changes test
//things still work
//TODO TEST add tests exercising failures
final List<DependencyStatus> deps = new LinkedList<>(blob.status());
final String version;
try {
final CommandResult bi = wsmongo.command("buildInfo");
version = bi.getString("version");
} catch (MongoException e) {
LoggerFactory.getLogger(getClass())
.error("Failed to connect to MongoDB", e);
deps.add(0, new DependencyStatus(false,
"Couldn't connect to MongoDB: " + e.getMessage(),
"MongoDB", "Unknown"));
return deps;
}
deps.add(0, new DependencyStatus(true, "OK", "MongoDB", version));
return deps;
}
示例3: check
import com.mongodb.CommandResult; //导入方法依赖的package包/类
@Override
protected Result check() throws Exception {
final BasicDBObject command = new BasicDBObject("buildInfo", 1);
final CommandResult commandResult = db.command(command);
if (!commandResult.ok()) {
return Result.unhealthy(commandResult.getErrorMessage());
}
final String version = commandResult.getString("version");
return Result.healthy("Mongo server version: %s", version);
}
示例4: isInShardCluster
import com.mongodb.CommandResult; //导入方法依赖的package包/类
private boolean isInShardCluster(
final CommandResult cr
) throws Exception {
MongoServer ms = new MongoServer(getMyself(cr));
final String host = ms.getHost();
final int port = ms.getPort();
boolean sharded = false;
final String msg = cr.getString("msg");
if ((msg != null) && msg.contains("isdbgrid")) {
sharded = true;
} else if (cr.getBoolean("ismaster")) {
final CommandResult shardState =
dbAdminCmd(host, port, "shardingState");
// shardingState command only returns OK when server is in a sharded
// cluster
if (shardState.ok()) {
if (shardState.getBoolean("enabled")) {
sharded = true;
}
}
} else if (cr.containsField("primary")) {
// we are in a replica set but not the primary,
// check the primary to see if it is a shard member
final String primary = cr.getString("primary");
ms = new MongoServer(primary);
final CommandResult priIsMaster =
dbAdminCmd(ms.getHost(), ms.getPort(), "isMaster");
sharded = isInShardCluster(priIsMaster);
}
return sharded;
}
示例5: getClusterNodeType
import com.mongodb.CommandResult; //导入方法依赖的package包/类
private String getClusterNodeType() throws Exception {
final String host = getStringProp(DB_HOST_PROP);
final int port = getIntProp(DB_PORT_PROP);
String nodeType = null;
final CommandResult isMaster = dbAdminCmd(host, port, "isMaster");
if (isMaster.getBoolean("ismaster")) {
final String msg = isMaster.getString("msg");
if (msg != null && msg.contains("isdbgrid")) {
nodeType = "shardRouter";
} else {
final CommandResult shardState =
dbAdminCmd(host, port, "shardingState");
if (shardState.ok() && shardState.getBoolean("enabled")) {
if (isConfigServer(host, port)) {
nodeType = "shardConfigServer";
} else {
nodeType = "shardMember";
}
}
}
} else if (isReplicaMember(isMaster)) {
nodeType = "shardMember";
}
return nodeType;
}
示例6: getConfigServersFromShard
import com.mongodb.CommandResult; //导入方法依赖的package包/类
private List<String> getConfigServersFromShard(
final String host,
final int port
) throws Exception {
final List<String> cfgServers = new ArrayList<String>();
String cHost = host;
int cPort = port;
final CommandResult isMaster = dbAdminCmd(cHost, cPort, "isMaster");
// we can't run the DB command "shardingState" from a node
// which isn't a master. This should only apply to non-primary
// replica members, so find the primary and run the command on it.
if (! isMaster.getBoolean("ismaster")) {
if (isMaster.containsField("primary")) {
final String primary = isMaster.getString("primary");
final MongoServer ms = new MongoServer(primary);
cHost = ms.getHost();
cPort = ms.getPort();
}
}
CommandResult shardState =
dbAdminCmd(cHost, cPort, "shardingState");
if (shardState.ok()) {
final String cfgSrvs =
shardState.getString("configServer");
addCommaSeparatedHosts(cfgServers, cfgSrvs);
}
return cfgServers;
}
示例7: getStoreVersion
import com.mongodb.CommandResult; //导入方法依赖的package包/类
public String getStoreVersion() {
CommandResult buildInfo = jongo.getDatabase().command("buildInfo");
return buildInfo.getString("version");
}
示例8: getServerVersion
import com.mongodb.CommandResult; //导入方法依赖的package包/类
/**
* Returns server version.
*
* @return Server version.
*/
@Nonnull
public String getServerVersion() {
final CommandResult result = db.doEval("db.version()");
return result.getString("retval");
}