Package com.mongodb

Examples of com.mongodb.CommandResult$CommandFailure


    String collection = StringUtils.hasText(collectionName) ? collectionName : determineCollectionName(entityClass);
    BasicDBObject command = new BasicDBObject("geoNear", collection);
    command.putAll(near.toDBObject());

    CommandResult commandResult = executeCommand(command);
    List<Object> results = (List<Object>) commandResult.get("results");
    results = results == null ? Collections.emptyList() : results;

    DbObjectCallback<GeoResult<T>> callback = new GeoNearResultDbObjectCallback<T>(new ReadDbObjectCallback<T>(
        mongoConverter, entityClass), near.getMetric());
    List<GeoResult<T>> result = new ArrayList<GeoResult<T>>(results.size());

    int index = 0;
    int elementsToSkip = near.getSkip() != null ? near.getSkip() : 0;

    for (Object element : results) {

      /*
       * As MongoDB currently (2.4.4) doesn't support the skipping of elements in near queries
       * we skip the elements ourselves to avoid at least the document 2 object mapping overhead.
       *
       * @see https://jira.mongodb.org/browse/SERVER-3925
       */
      if (index >= elementsToSkip) {
        result.add(callback.doWith((DBObject) element));
      }
      index++;
    }

    if (elementsToSkip > 0) {
      // as we skipped some elements we have to calculate the averageDistance ourselves:
      return new GeoResults<T>(result, near.getMetric());
    }

    DBObject stats = (DBObject) commandResult.get("stats");
    double averageDistance = stats == null ? 0 : (Double) stats.get("avgDistance");
    return new GeoResults<T>(result, new Distance(averageDistance, near.getMetric()));
  }
View Full Code Here


    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Executing MapReduce on collection [" + command.getInput() + "], mapFunction [" + mapFunc
          + "], reduceFunction [" + reduceFunc + "]");
    }

    CommandResult commandResult = command.getOutputType() == MapReduceCommand.OutputType.INLINE ? executeCommand(
        commandObject, getDb().getOptions()) : executeCommand(commandObject);
    handleCommandError(commandResult, commandObject);

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("MapReduce command result = [{}]", serializeToJsonSafely(commandObject));
View Full Code Here

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Executing Group with DBObject [{}]", serializeToJsonSafely(commandObject));
    }

    CommandResult commandResult = executeCommand(commandObject, getDb().getOptions());
    handleCommandError(commandResult, commandObject);

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Group command result = [{}]", commandResult);
    }

    @SuppressWarnings("unchecked")
    Iterable<DBObject> resultSet = (Iterable<DBObject>) commandResult.get("retval");
    List<T> mappedResults = new ArrayList<T>();
    DbObjectCallback<T> callback = new ReadDbObjectCallback<T>(mongoConverter, entityClass);

    for (DBObject dbObject : resultSet) {
      mappedResults.add(callback.doWith(dbObject));
View Full Code Here

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Executing aggregation: {}", serializeToJsonSafely(command));
    }

    CommandResult commandResult = executeCommand(command);
    handleCommandError(commandResult, command);

    return new AggregationResults<O>(returnPotentiallyMappedResults(outputType, commandResult), commandResult);
  }
View Full Code Here

  }

  private void queryMongoVersionIfNecessary() {

    if (mongoVersion == null) {
      CommandResult result = mongoTemplate.executeCommand("{ buildInfo: 1 }");
      mongoVersion = Version.parse(result.get("version").toString());
    }
  }
View Full Code Here

  public void setPassword(String password) {
    this.password = password;
  }

  public CommandResult getServerStatus() {
    CommandResult result = getDb("admin").command("serverStatus");
    if (!result.ok()) {
      logger.error("Could not query for server status.  Command Result = " + result);
      throw new MongoException("could not query for server status.  Command Result = " + result);
    }
    return result;
  }
View Full Code Here

  }

  private void queryMongoVersionIfNecessary() {

    if (mongoVersion == null) {
      CommandResult result = template.executeCommand("{ buildInfo: 1 }");
      mongoVersion = org.springframework.data.util.Version.parse(result.get("version").toString());
    }
  }
View Full Code Here

    if (currentVersion == null) {
      try {
        MongoClient client;
        client = new MongoClient(host, port);
        DB db = client.getDB("test");
        CommandResult result = db.command(new BasicDBObjectBuilder().add("buildInfo", 1).get());
        this.currentVersion = Version.parse(result.get("version").toString());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
View Full Code Here

  }

  @Test
  public void serverStats() {
    // CommandResult result = testAdminDb.getStats();
    CommandResult result = mongo.getDB("admin").command("serverStatus");
    logger.info("stats = " + result);
  }
View Full Code Here

    if(!db.getCollectionNames().contains(OLD_DOCUMENT_COLLECTION)) {
      BasicDBObject dbo = new BasicDBObject("create", OLD_DOCUMENT_COLLECTION);
      dbo.put("capped", true);
      dbo.put("size", size);
      dbo.put("max", max);
      CommandResult cr = db.command(dbo);
      if(cr.ok()) {
        logger.info("Created a capped collection for old documents with {size: "+size+", max: "+max+"}");
      }
      else {
        if(db.getCollectionNames().contains(OLD_DOCUMENT_COLLECTION)) {
          logger.debug("Raced to create "+OLD_DOCUMENT_COLLECTION+" collection and lost");
View Full Code Here

TOP

Related Classes of com.mongodb.CommandResult$CommandFailure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.