当前位置: 首页>>代码示例>>Java>>正文


Java CommandResult.get方法代码示例

本文整理汇总了Java中com.mongodb.CommandResult.get方法的典型用法代码示例。如果您正苦于以下问题:Java CommandResult.get方法的具体用法?Java CommandResult.get怎么用?Java CommandResult.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.CommandResult的用法示例。


在下文中一共展示了CommandResult.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getShards

import com.mongodb.CommandResult; //导入方法依赖的package包/类
/**
 * get list of  the shards
 * @param dbConn
 * @return
 */
private static List<String> getShards(DB dbConn) {
    List<String> shards = new ArrayList<String>();

    DBObject listShardsCmd = new BasicDBObject("listShards", 1);
    CommandResult res = dbConn.command(listShardsCmd);
    if (!res.ok()) {
        LOG.error("Error getting shards for {}: {}", dbConn, res.getErrorMessage());
    }

    BasicDBList listShards = (BasicDBList) res.get("shards");

    //Only get shards for sharding mongo
    if (listShards != null) {
        ListIterator<Object> iter = listShards.listIterator();

        while (iter.hasNext()) {
            BasicDBObject shard = (BasicDBObject) iter.next();
            shards.add(shard.getString(ID));
        }
    }
    return shards;
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:28,代码来源:MongoCommander.java

示例2: setup

import com.mongodb.CommandResult; //导入方法依赖的package包/类
private void setup() throws UnknownHostException {
    if (isInitialized()) {
        mongoClient = new MongoClient(mongoUri);
    }

    try {
        CommandResult res = mongoClient.getDB("admin").command("buildInfo");
        Object _version = res.get("version");

        if (_version != null && _version instanceof String) {
            serverVersion = (String) _version;
        } else {
            LOGGER.warn("Cannot get the MongoDb version.");
            serverVersion = "3.x?";
        }
    } catch (Throwable t) {
        LOGGER.warn("Cannot get the MongoDb version.");
        serverVersion = "?";
    }
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:21,代码来源:MongoDBClientSingleton.java

示例3: check

import com.mongodb.CommandResult; //导入方法依赖的package包/类
@Override
protected Result check() throws Exception {
	MongoClient mongoClient = null;
	String databaseList = null;
	String databaseStats = null;

	try {
		mongoClient = createMongoClient();
		MongoIterable<String> dbList = mongoClient.listDatabaseNames();
		databaseList = StringUtils.join(dbList, ',');

		CommandResult resultSet = mongoClient.getDB(databaseName).getStats();
		databaseStats = resultSet.toString();
		logger.debug("connectionUrl={} databaseList={} stats={}", connectionUrl, databaseList, databaseStats);

		Integer nbrCollections = (Integer) resultSet.get("collections");
		if (nbrCollections == 0) {
			throw new RuntimeException("Database has nothing in it.");
		}
	} catch (Exception e) {
		ContextedRuntimeException wrappedException = wrapException(e);
		wrappedException.addContextValue("databaseList", databaseList);
		wrappedException.addContextValue("databaseStats", databaseStats);

		logger.error("MongoDB Healthcheck Failure", wrappedException);
		return Result.unhealthy(wrappedException);
	} finally {
		closeQuietly(mongoClient);
	}

	return Result.healthy();
}
 
开发者ID:BreakTheMonolith,项目名称:btm-DropwizardHealthChecks,代码行数:33,代码来源:MongoDbHealthCheck.java

示例4: getShardsFromMongos

import com.mongodb.CommandResult; //导入方法依赖的package包/类
private List<String> getShardsFromMongos(
    final String host,
    final int port
) throws Exception {

    final List<String> shardResult = new ArrayList<String>();

    final CommandResult cr = dbAdminCmd(host, port, "listShards");

    if (cr.ok()) {
        final BasicDBList shardList= (BasicDBList)cr.get("shards");
        for (Object obj : shardList) {
            final BasicDBObject bdbo = (BasicDBObject) obj;
            String shards = bdbo.getString("host");
            if (shards.indexOf("/") != -1) {
                final String [] shardMembers =
                    shards.split("/")[1].split(",");
                for (String member : shardMembers) {
                    final MongoServer ms =
                        new MongoServer(member);
                    shardResult.addAll(discoverReplicas(
                            ms.getHost(), ms.getPort()));
                }
            } else {
                // single node shard
                shardResult.add(shards);
            }
        }
    }
    return shardResult;
}
 
开发者ID:CA-APM,项目名称:ca-apm-fieldpack-mongodb,代码行数:32,代码来源:ShardCluster.java

示例5: getSplitData

import com.mongodb.CommandResult; //导入方法依赖的package包/类
/**
 * Gets split data.
 *
 * @param collection the collection
 * @return the split data
 */
private BasicDBList getSplitData(DBCollection collection) {

    final DBObject cmd = BasicDBObjectBuilder.start("splitVector", collection.getFullName())
            .add("keyPattern", new BasicDBObject(MONGO_DEFAULT_ID, 1))
            .add("force", false)
            .add("maxChunkSize", splitSize)
            .get();

    CommandResult splitVectorResult = collection.getDB().getSisterDB("admin").command(cmd);
    return (BasicDBList) splitVectorResult.get(SPLIT_KEYS);

}
 
开发者ID:Stratio,项目名称:deep-spark,代码行数:19,代码来源:MongoNativeExtractor.java

示例6: bounceMongos

import com.mongodb.CommandResult; //导入方法依赖的package包/类
private static void bounceMongos() throws IOException, InterruptedException {
	// get the command line args
	CommandResult result = Config.get_adminDB().command("getCmdLineOpts");

	// build the command line and restart mongos on this host
	StringBuilder sb = new StringBuilder();
	BasicDBList list = (BasicDBList) result.get("argv");
	String[] argv = new String[list.size()];
	for (int i = 0; i < list.size(); i++) {
		sb.append(list.get(i));
		sb.append(" ");
		argv[i] = list.get(i).toString();
	}

	// shutdown mongos
	MessageLog.push("Shutting down mongos...", Resharder.class.getSimpleName());

	try {
		result = Config.get_adminDB().command(new BasicDBObject("shutdown", 1));
	} catch (Exception e) {
		// NOOP we probably ended up here because the server went
		// away before we could get a result
	}

	MessageLog.push("Restarting mongos.  cmdLine: " + sb.toString(), Resharder.class.getSimpleName());
	Runtime.getRuntime().exec(argv);

	// let things settle down and initialize
	Thread.sleep(5000);

	// restart Balancer
	MessageLog.push("Restarting Balancer...", Resharder.class.getSimpleName());
	result = Config.get_adminDB().doEval("function() {sh.setBalancerState(true); return sh.getBalancerState();}",
			new Object[0]);

	if (Boolean.parseBoolean(result.toString())) {
		MessageLog.push("ERUnable to start Balancer", Resharder.class.getSimpleName());
	}
}
 
开发者ID:rhoulihan,项目名称:resharder,代码行数:40,代码来源:Resharder.java

示例7: doUpdate

import com.mongodb.CommandResult; //导入方法依赖的package包/类
public boolean doUpdate(Query query, Update update) {
    DBObject queryDBObject = toSubDocQuery(query, true);

    DBObject elementMatch = new BasicDBObject("$elemMatch", query.getQueryObject());
    queryDBObject.put(subField, elementMatch);

    DBObject patchUpdate = toSubDocUpdate(update);
    String updateCommand = "{findAndModify:\"" + collection + "\",query:" + queryDBObject.toString()
            + ",update:" + patchUpdate.toString() + "}";
    LOG.debug("the update date mongo command is: {}", updateCommand);
    TenantContext.setIsSystemCall(false);
    CommandResult result = template.executeCommand(updateCommand);
    return result.get("value") != null;

}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:16,代码来源:SubDocAccessor.java

示例8: findSubDocs

import com.mongodb.CommandResult; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
        private List<Entity> findSubDocs(DBObject parentQuery, DBObject limitQuery) {
            StringBuilder limitQuerySB = new StringBuilder();
            if (limitQuery != null && limitQuery.keySet().size() > 0) {
                if (limitQuery.get("$sort") != null) {
                    limitQuerySB.append(",{$sort:" + limitQuery.get("$sort").toString() + "}");
                }
                if (limitQuery.get("$skip") != null) {
                    limitQuerySB.append(",{$skip:" + limitQuery.get("$skip") + "}");
                }
                if (limitQuery.get("$limit") != null) {
                    limitQuerySB.append(",{$limit:" + limitQuery.get("$limit") + "}");
                }
            }
            simplifyParentQuery(parentQuery);

            DBObject idQuery = buildIdQuery(parentQuery);
//            String queryCommand = buildAggregateQuery(idQuery != null ? idQuery.toString() : parentQuery.toString(),
//                    parentQuery.toString(), limitQuerySB.toString());
            String queryCommand;
            if (idQuery == null) {
                queryCommand = buildAggregateQuery(parentQuery.toString(), null, limitQuerySB.toString());
            } else {
                queryCommand = buildAggregateQuery(idQuery.toString(), parentQuery.toString(), limitQuerySB.toString());
            }
            TenantContext.setIsSystemCall(false);
            CommandResult result = template.executeCommand(queryCommand);
            List<DBObject> subDocs = (List<DBObject>) result.get("result");
            List<Entity> entities = new ArrayList<Entity>();

            if (subDocs != null && subDocs.size() > 0) {
                for (DBObject dbObject : subDocs) {
                    entities.add(convertDBObjectToSubDoc(((DBObject) dbObject.get(subField))));
                }
            }
            return entities;
        }
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:38,代码来源:SubDocAccessor.java

示例9: aggregate

import com.mongodb.CommandResult; //导入方法依赖的package包/类
private <T> List<T> aggregate(String statement, Object[] parameter, ResultHandler handler, ReadPreference readPreference) {
  logger.debug("Execute 'aggregate' mongodb command. Statement '" + statement + "'.");

  AggregateConfig config = (AggregateConfig) configuration.getConfig(statement);
  if (config == null) {
    throw new MongoDaoException(statement, "Aggregate statement id '" + statement + "' not found.");
  }

  String collection = config.getCollection();
  Map<String, NodeEntry> function = config.getFunction();
  NodeEntry field = config.getField();

  DB db = factory.getDataSource().getDB();

  DBCollection coll = db.getCollection(collection);
  coll.setReadPreference(readPreference);

  NodeEntry firstFunction = function.remove(0);
  Map<String, Object> f = (Map<String, Object>) firstFunction.executorNode(configuration, parameter);
  DBObject firstOp = new BasicDBObject(f);
  logger.debug("Execute 'aggregate' mongodb command. First Operation '" + firstOp + "'.");

  DBObject[] operations = new DBObject[function.size()];
  for (int i = 0; i < function.size(); i++) {
    NodeEntry ne = function.get(i);
    Map<String, Object> op = (Map<String, Object>) ne.executorNode(configuration, parameter);
    DBObject operationDbo = new BasicDBObject(op);
    operations[i] = operationDbo;
    logger.debug("Execute 'aggregate' mongodb command. Operation '" + operationDbo + "'.");
  }

  CommandResult commandResult = coll.aggregate(firstOp, operations).getCommandResult();
  logger.debug("Execute 'aggregate' mongodb command. Result set '" + commandResult + "'.");

  final BasicDBList resultSet = (BasicDBList) commandResult.get("result");
  if (handler != null) {
    handler.handleResult(new ResultContext() {
      @Override
      public Object getResultObject() {
        return resultSet;
      }
      
      @Override
      public int getResultCount() {
        return resultSet.size();
      }
    });
    return null;
  }
  
  List<T> list = new ArrayList<T>(resultSet.size());
  for (Iterator iter = resultSet.iterator(); iter.hasNext();) {
    T result = (T) helper.toResult(field, iter.next());
    list.add(result);
  }
  return list;
}
 
开发者ID:yuxiangping,项目名称:mongodb-orm,代码行数:58,代码来源:MongoClientTemplet.java


注:本文中的com.mongodb.CommandResult.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。