Package com.mongodb

Examples of com.mongodb.CommandResult


      // (never any content)
      BasicDBObject query = new BasicDBObject(DocumentPojo.sourceUrl_, sourceUrl);
      query.put(DocumentPojo.sourceKey_, sourceKey);
      BasicDBObject softDeleter = getSoftDeleteUpdate();
      DbManager.getDocument().getMetadata().update(query, softDeleter, false, true);
      CommandResult result = DbManager.getDocument().getLastError("metadata");
     
      // Quick delete for index though:
      if (!communityId.equals(_cachedCommunityIdForSourceXxxDeletion)) {
        StringBuffer sb = new StringBuffer(DocumentPojoIndexMap.manyGeoDocumentIndexCollection_).append(",docs_").append(communityId).append('/').append(DocumentPojoIndexMap.documentType_);
        _cachedIndexManagerForSourceXxxDeletion = IndexManager.getIndex(sb.toString());
        _cachedCommunityIdForSourceXxxDeletion = communityId;
      }//TESTED
      _cachedIndexManagerForSourceXxxDeletion.doDeleteByQuery(
          QueryBuilders.boolQuery()
            .must(QueryBuilders.termQuery(DocumentPojo.sourceUrl_, sourceUrl))
            .must(QueryBuilders.termQuery(DocumentPojo.sourceKey_, sourceKey))
          );
     
      return result.getLong("n", 0);
     
    } catch (Exception e) {
      // If an exception occurs log the error
      logger.error("Exception Message: " + e.getMessage(), e);     
    }
View Full Code Here


   
    // Recreate the index, size will depend on the size of the collection
   
    DBCollection outputCollection = DbManager.getCollection(job.getOutputDatabase(), outputCollectionToUse);
    long collectionSize = 1L;
    CommandResult outputCollectionStats = outputCollection.getStats();
    if (null != outputCollectionStats) {
      collectionSize = outputCollectionStats.getLong("size", 1L);
    }
    // Let's say 1 shard/500MB
    final long SHARD_SIZE = 500L*1024L*1024L;
    int numShards = 1 + (int)(collectionSize/SHARD_SIZE);
    if (appendMode) { // increase the size for the future shards=1 + 2*(initial size + 1)
View Full Code Here

              if ((null == savedQuery.getQueryInfo().getLastRun()) ||
                  ((nowTime - savedQuery.getQueryInfo().getLastRun().getTime()) > freqOffset))
              {
                //(does nothing if the share already exists)
                DbManager.getCustom().getSavedQueryCache().insert(savedQueryShare.toDb());
                CommandResult cr = DbManager.getCustom().getSavedQueryCache().getDB().getLastError();
               
                if (null == cr.get("err")) { // if we've actually done something, update the main share table also
                  savedQuery.getQueryInfo().setLastRun(now);
                  savedQueryShare.setShare(savedQuery.toApi());
                  // (this will overwrite the existing version)
                  DbManager.getSocial().getShare().save(savedQueryShare.toDb());               
                }//TESTED (by hand with prints)
View Full Code Here

    String location = null;
    BasicDBObject command = new BasicDBObject("geoNear", "geo");
    Double[] coordinates = {lat,lon};
    command.put("near", coordinates);
    command.put("maxDistance", MAXIMUM_DISTANCE_IN_METERS);
    CommandResult commandResult = MongoDbManager.getDB("feature").command(command);
    if ( commandResult.ok() && commandResult.containsField("results") )
    {
      BasicDBList results = (BasicDBList)commandResult.get("results");
      return results;     
    }
   
    return null;
  }
View Full Code Here

            @Override
            public Object doRun() {
//                output = col.mapReduce(cmd);

                // if type in inline, then query options like slaveOk is fine
                CommandResult res = null;
                if (type == MapReduceCommand.OutputType.INLINE) {
                    res = col.getDB().command(cmdobj, col.getOptions());
                    return res;
                }

                res = col.getDB().command(cmdobj);
                res.throwOnError();
                output = new MapReduceOutput(col, cmdobj, res);
                return output;
            }

            @Override
View Full Code Here

            label += " (" + stats.getInt("count") + "/" + stats.getInt("size") + ")";
    }

    @Override
    protected void refreshNode() {
        CommandResult res = getStatsCollection().getStats();
        res.throwOnError();
        stats = res;
    }
View Full Code Here

            }
            if (logRes) {
                logObj.put("firstResult", lasterr);
            }
        } else if (res instanceof CommandResult) {
            CommandResult cres = (CommandResult) res;
            if (!cres.ok()) {
                UMongo.instance.showError(title, (Exception) cres.getException());
            }
            new DocView(null, title, this, sroot, (DBObject) res).addToTabbedDiv();
            if (logRes) {
                logObj.put("firstResult", res.toString());
            }
View Full Code Here

            label += "?";
    }

    @Override
    protected void refreshNode() {
        CommandResult res = getServerMongoClient().getDB("local").command("isMaster");
        res.throwOnError();
        stats = res;
    }
View Full Code Here

                            DBCollection svrcol = svrm.getDB(dbname).getCollection(colname);
                            long value = 0;
                            if (stat.startsWith("Count")) {
                                value = svrcol.count();
                            } else if (stat.startsWith("Data Size")) {
                                CommandResult stats = svrcol.getStats();
                                value = stats.getLong("size");
                            }
                            values.append(svrm.getConnectPoint(), value);
                            if (ref < 0)
                                ref = value;
                            else if (ref != value)
View Full Code Here

        xmlLoad(Resource.getXmlDir(), Resource.File.routerNode, null);
    }

    @Override
    protected void populateChildren() {
        CommandResult res = mongo.getDB("admin").command("listShards");
        shards = (BasicDBList) res.get("shards");
        if (shards == null) {
            return;
        }

        for (Object obj : shards) {
            try {
                DBObject shard = (DBObject) obj;
                String shardName = (String) shard.get("_id");
                String hosts = (String) shard.get("host");
                String repl = null;
                int slash = hosts.indexOf('/');
                if (slash >= 0) {
                    repl = hosts.substring(0, slash);
                    hosts = hosts.substring(slash + 1);
                }

                String[] hostList = hosts.split(",");
                ArrayList<ServerAddress> addrs = new ArrayList<ServerAddress>();
                for (String host : hostList) {
                    int colon = host.indexOf(':');
                    if (colon >= 0) {
                        addrs.add(new ServerAddress(host.substring(0, colon), Integer.parseInt(host.substring(colon + 1))));
                    } else {
                        addrs.add(new ServerAddress(host));
                    }
                }

                if (repl != null || addrs.size() > 1) {
                    addChild(new ReplSetNode(repl, addrs, mongo.getMongoClientOptions(), shardName));
                } else {
                    addChild(new ServerNode(addrs.get(0), mongo.getMongoClientOptions(), false, false));
                }
            } catch (Exception e) {
                getLogger().log(Level.WARNING, null, e);
            }
        }

        // add config servers
        try {
            res = mongo.getDB("admin").command("getCmdLineOpts");
            String configStr = (String) ((BasicDBObject) res.get("parsed")).get("configdb");
            String[] configsvrs = configStr.split(",");
            for (String host : configsvrs) {
                int colon = host.indexOf(':');
                ServerAddress addr;
                if (colon >= 0) {
View Full Code Here

TOP

Related Classes of com.mongodb.CommandResult

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.