List of usage examples for com.mongodb Mongo getDB
@Deprecated public DB getDB(final String dbName)
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestRunCommand.java
License:Open Source License
/** * @param args// w ww . j a va2 s. c o m */ public static void main(String[] args) throws Exception { ConAndAuthentication testMongoCls = new ConAndAuthentication(); Mongo mongo = testMongoCls.connection(ConAndAuthentication.serverurl, 27017);//ConAndAuthentication.port); DB db = mongo.getDB("test"); DBCollection dbColl = db.getCollection("user"); DBObject cmdObj = (DBObject) JSON.parse("{language : 'en_us'}, {seq: true, email:true}, {seq, -1}"); DBCursor dbCur = dbColl.find(cmdObj); for (DBObject obj : dbCur.toArray()) { System.out.println(obj); } // CommandResult cr = db.command(cmdObj);//new BasicDBObject("create", "hyunjong")); // System.out.println( cr.toString() ); mongo.close(); }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestServerSideJavascript.java
License:Open Source License
/** * @param args//from ww w .j av 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"); createServerSideJavaScript(db); updateServerSideJavaScript(db, "addNumbers", "update java script"); findAllServerSideJavaScript(db); Object[] arryArgs = { 25, 34 }; evalServerSideJavaScript(db, "addNumbers2", arryArgs); mongo.close(); try { Thread.sleep(1); } catch (Exception e) { } }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestServerStatus.java
License:Open Source License
/** * @param args/*from w ww .jav a 2s . co 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/*from www .j ava 2 s. c om*/ */ 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 ww w .j a va 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("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.hangum.tadpole.mongodb.core.test.MongoTestUpdateCollection.java
License:Open Source License
/** * @param args//from www . j a va2 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"); DBCollection collAddress = db.getCollection("test555"); BasicDBObject findObj = new BasicDBObject().append("n", 2); DBCursor cur = collAddress.find(findObj); DBObject dbObj = cur.next(); System.out.println(dbObj); System.out.println("================================================================================"); if (dbObj != null) { BasicDBObject newDocument3 = new BasicDBObject().append("$set", new BasicDBObject().append("allPlans.0.cursor", "t2est")); // allPlans.0.cursor WriteResult wr = collAddress.update(dbObj, newDocument3); } // // System.out.println(wr.toString()); // mongo.close(); }
From source file:com.hangum.tadpole.mongodb.core.test.ReplicaSetConnnection.java
License:Open Source License
/** * db ? //from w w w . j a v a2 s . c om * * @param args */ public static void main(String[] args) { try { ReplicaSetConnnection testMongoCls = new ReplicaSetConnnection(); Mongo mongo = testMongoCls.connection(serverurl, port); System.out.println(""); if (mongo != null) { DB testDB = mongo.getDB("test"); // Set<String> collectionNames = // testMongoCls.getCollectionNames(testDB); // for (String collection : collectionNames) { testMongoCls.getCollectionInfo(testDB, "store"); // } } // mongo.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.hangum.tadpole.mongodb.erd.core.dnd.TableTransferDropTargetListener.java
License:Open Source License
/** * table? .//w w w . j a va 2s . c om * * @param strTBName * @return * @throws Exception */ public List<CollectionFieldDAO> getColumns(String strTBName) throws Exception { Mongo mongo = new Mongo(new DBAddress(userDB.getUrl())); com.mongodb.DB mongoDB = mongo.getDB(userDB.getDb()); DBCollection coll = mongoDB.getCollection(strTBName); return MongoDBTableColumn.tableColumnInfo(coll.getIndexInfo(), coll.findOne()); }
From source file:com.hangum.tadpole.rdb.core.viewers.object.ExplorerViewer.java
License:Open Source License
/** * table .//from ww w. ja v a 2 s . co m */ public void refreshTable(final String source) { try { if (DBDefine.getDBDefine(userDB.getTypes()) != DBDefine.MONGODB_DEFAULT) { SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB); showTables = sqlClient.queryForList("tableList", userDB.getDb()); //$NON-NLS-1$ // mongo db } else if (DBDefine.getDBDefine(userDB.getTypes()) == DBDefine.MONGODB_DEFAULT) { Mongo mongo = new Mongo(new DBAddress(userDB.getUrl())); DB mongoDB = mongo.getDB(userDB.getDb()); if (showTables != null) showTables.clear(); else showTables = new ArrayList<TableDAO>(); for (String col : mongoDB.getCollectionNames()) { TableDAO dao = new TableDAO(); dao.setName(col); showTables.add(dao); } } tableListViewer.setInput(showTables); tableListViewer.refresh(); } catch (Exception e) { logger.error(source + " Table Referesh", e); if (showTables != null) showTables.clear(); tableListViewer.setInput(showTables); tableListViewer.refresh(); Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$ if ("DB".equals(source)) //$NON-NLS-1$ ExceptionDetailsErrorDialog.openError(getSite().getShell(), "Error", Messages.ExplorerViewer_4, //$NON-NLS-1$ errStatus); else ExceptionDetailsErrorDialog.openError(getSite().getShell(), "Error", Messages.ExplorerViewer_86, //$NON-NLS-1$ errStatus); } }
From source file:com.howbuy.appframework.homo.configure.commons.jdbc.datasource.DriverManagerDataSource.java
License:Apache License
/** * ?MongoDB/*ww w .j av a2 s .co m*/ * @param conn * @return * @throws Exception */ protected DB getConnectionFromDriverManagerMongoDB(Connection conn) throws Exception { String[] dataArray = getConnectionFromStringArr(conn); String[] mongoDBConn = dataArray[1].split(","); Mongo m = new Mongo(mongoDBConn[0], (new Integer(mongoDBConn[1])).intValue()); DB db = m.getDB(mongoDBConn[2]); if (dataArray[2] != null && !dataArray[2].equals("") && dataArray[3] != null && !dataArray[3].equals("")) { char[] pwd = dataArray[3].toCharArray(); db.authenticate(dataArray[2], pwd); } if (mongoDBConn.length > 3 && mongoDBConn[3] != null && !mongoDBConn[3].equals("")) { db = m.getDB(mongoDBConn[3]); } return db; }