List of usage examples for com.mongodb CommandResult ok
public boolean ok()
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestProfilling.java
License:Open Source License
/** * @param args/*www. jav a 2 s . c o m*/ */ public static void main(String[] args) throws Exception { ConAndAuthentication testMongoCls = new ConAndAuthentication(); Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port); DB db = mongo.getDB("test"); // ?? System.out.println("####[profilling ]######################################################"); CommandResult cr = db.command(new BasicDBObject("profile", 0)); System.out.println("[ok]" + cr.ok()); if (!cr.ok()) System.out.println("[Exception ]" + cr.getException().toString()); System.out.println("[toString]" + JSONUtil.getPretty(cr.toString())); System.out.println("[size]" + cr.size()); System.out.println("####[profilling ]######################################################"); // ? System.out.println( "####[profilling collections ]######################################################"); if (db.collectionExists("system.profile")) { DBCollection profileColl = db.getCollection("system.profile"); profileColl.drop(); } System.out.println( "####[profilling collections ]######################################################"); // ? // system.profile collection ? System.out.println( "####[profilling collections ? ]######################################################"); DBObject dbObject = (DBObject) JSON.parse("{capped:true, size:8000000}"); DBCollection dbColl = db.createCollection("system.profile", dbObject); BasicDBObject newProfileColl = (BasicDBObject) dbColl.getStats().copy(); System.out.println( "####[profilling collections ? ]######################################################"); // system.profile collection ? System.out.println("####[profilling ]######################################################"); cr = db.command(new BasicDBObject("profile", 2)); System.out.println("[ok]" + cr.ok()); if (!cr.ok()) System.out.println("[Exception ]" + cr.getException().toString()); System.out.println("[toString]" + JSONUtil.getPretty(cr.toString())); System.out.println("[size]" + cr.size()); System.out.println("####[profilling ]######################################################"); // //####################################################################################################### // //####################################################################################################### // //####################################################################################################### System.out.println("####[start profilling result]######################################################"); DBCollection myColl = db.getCollection("system.profile"); BasicDBObject query = new BasicDBObject(); query.put("millis", new BasicDBObject("$gt", 4)); DBCursor myCursor = myColl.find(); while (myCursor.hasNext()) { DBObject dbObj = myCursor.next(); System.out.println(dbObj.get("ts") + " - " + dbObj.get("ns") + " - " + dbObj.get("nscanned") + "/" + dbObj.get("nreturned") + " millis :" + dbObj.get("millis")); } System.out.println("####[end profilling result]######################################################"); mongo.close(); }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestReIndex.java
License:Open Source License
/** * @param args/*www . j a v a2 s. c om*/ */ public static void main(String[] args) throws Exception { ConAndAuthentication testMongoCls = new ConAndAuthentication(); Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port); DB db = mongo.getDB("test"); DBObject queryObj = new BasicDBObject("reIndex", "store"); CommandResult cr = db.command(queryObj); System.out.println("[ok]" + cr.ok()); if (!cr.ok()) System.out.println("[Exception ]" + cr.getException().toString()); System.out.println("[toString]" + cr.toString()); System.out.println("[size]" + cr.size()); mongo.close(); }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestServerStatus.java
License:Open Source License
/** * @param args/*from ww w. jav a2 s . c o m*/ */ public static void main(String[] args) throws Exception { ConAndAuthentication testMongoCls = new ConAndAuthentication(); Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port); DB db = mongo.getDB("test"); DBObject queryObj = new BasicDBObject("serverStatus", 0); CommandResult cr = db.command(queryObj); String strHost = cr.getString("host"); String version = cr.getString("version"); String process = cr.getString("process"); String pid = cr.getString("pid"); String uptime = cr.getString("uptime"); String uptimeMillis = cr.getString("uptimeMillis"); String uptimeEstimate = cr.getString("uptimeEstimate"); String localTime = cr.getString("localTime"); System.out.println("[strHost]\t " + strHost); System.out.println("[version]\t " + version); System.out.println("[process]\t " + process); System.out.println("[pid]\t " + pid); System.out.println("[uptime]\t " + uptime); System.out.println("[uptimeMillis]\t " + uptimeMillis); System.out.println("[uptimeEstimate]\t " + uptimeEstimate); System.out.println("[localTime]\t " + localTime); System.out.println("[ok]" + cr.ok()); if (!cr.ok()) System.out.println("[Exception ]" + cr.getException().toString()); System.out.println("[toString]" + cr.toString()); System.out.println("[size]" + cr.size()); mongo.close(); }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestShardInformation.java
License:Open Source License
/** * @param args/* www . j av a 2 s . co m*/ */ public static void main(String[] args) throws Exception { ConAndAuthentication testMongoCls = new ConAndAuthentication(); Mongo mongo = testMongoCls.connection("127.0.0.1", 27018); DB db = mongo.getDB("admin"); DBObject queryObj = new BasicDBObject("listshards", 1); CommandResult cr = db.command(queryObj); if (cr.ok()) { System.out.println(cr.toString()); } else { System.out.println(cr.getException()); } // shard key ?? ? ? . final BasicDBObject shardKey = new BasicDBObject("TrackId", 1); final BasicDBObject cmd = new BasicDBObject("shardcollection", "test.Track"); cmd.put("key", shardKey); CommandResult result4 = mongo.getDB("admin").command(cmd); System.out.println("====>" + result4); }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestTop.java
License:Open Source License
/** * @param args//from w w w . j a va 2 s .c om */ public static void main(String[] args) throws Exception { ConAndAuthentication testMongoCls = new ConAndAuthentication(); Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, ConAndAuthentication.port); DB db = mongo.getDB("admin"); DBObject queryObj = new BasicDBObject("top", 1); CommandResult cr = db.command(queryObj); if (cr.ok()) { System.out.println(cr.toString()); } else { System.out.println(cr.getException()); } }
From source file:com.ikanow.infinit.e.api.knowledge.SearchHandler.java
License:Open Source License
/** * Sends a geonear command to the feature.geo database. Returns back * a list of the nearest 10 locations//w w w .ja va2s . c o m * * @param lat * @param lon * @return */ private BasicDBList runGeoNear(Double lat, Double lon) { 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; }
From source file:com.jaspersoft.mongodb.query.MongoDbQueryWrapper.java
License:Open Source License
private void runCommand(Object commandValue) throws JRException { if (!(commandValue instanceof DBObject)) { throw new JRException("Command must be a valid BSON object"); }/*from w ww . jav a2 s . co m*/ DBObject commandObject = (DBObject) commandValue; if (logger.isDebugEnabled()) { logger.debug("Command object: " + commandObject); } CommandResult commandResult = connection.getMongoDatabase().command(commandObject); if (!commandResult.ok()) { throw new JRException(commandResult.getErrorMessage()); } Object resultObject = commandResult.get(RESULT_KEY); if (resultObject == null) { throw new JRException("No results"); } commandResults = (List<?>) resultObject; }
From source file:com.jaspersoft.mongodb.query.MongoDbQueryWrapper.java
License:Open Source License
public static void main(String[] args) { MongoDbConnection c = null;/* ww w .ja v a 2 s . com*/ ReportTest reports = new ReportTest(); try { c = new MongoDbConnection("mongodb://localhost:27017/test", null, null); reports.test(); Object cmd = JSON.parse("{\n" + " aggregate : \"accounts\",\n" + " pipeline : [\n" + " {\n" + " $project : {\n" + " billing_address_street : 1,\n" + " billing_address_country : 1\n" + " }\n" + " }\n" + " ]\n" + " }"); CommandResult result = c.getMongoDatabase().command((DBObject) cmd); System.out.println(result.keySet()); System.out.println(result.get("ok") + " - " + result.ok()); System.out.println(result.get("result").getClass().getName()); } catch (Exception e) { logger.error(e); } finally { if (c != null) { c.close(); } } }
From source file:com.jhkt.playgroundArena.shared.tasks.MongoDBTaskRunner.java
License:Apache License
private void processWriteResult(WriteResult wr) { CommandResult result = wr.getLastError(); if (!result.ok()) { throw new RuntimeException(result.getErrorMessage(), result.getException()); }//from www . j a va 2 s .c o m }
From source file:com.nec.strudel.tkvs.store.mongodb.MongodbLifecycle.java
License:Apache License
@Override public void prepare() { showBalancerLock();/*from w w w . j av a 2 s . com*/ int sleepSec = getIntOpt(PROP_SLEEP_AFTER_SEC, 0); if (sleepSec > 0) { LOGGER.info("sleeping " + sleepSec + " seconds..."); sleep(sleepSec); LOGGER.info("sleeping done."); showBalancerLock(); } DB db = mongoClient.getDB(dbName); LOGGER.info("getting DB stats: " + dbName); CommandResult res = db.getStats(); if (res.ok()) { LOGGER.info("DB stats OK: " + res); } else { LOGGER.warn("DB stats NG: " + res); } DBCollection coll = db.getCollection(dbName); LOGGER.info("getting Collection stats: " + dbName); res = coll.getStats(); if (res.ok()) { LOGGER.info("Collection stats OK: " + res); } else { LOGGER.warn("Collection stats NG: " + res); } }