List of usage examples for com.mongodb Mongo Mongo
@Deprecated
public Mongo()
From source file:net.sf.okapi.lib.tmdb.mongodb.Repository.java
License:Open Source License
/** * Helper method to delete existing repository * @param repoName//from www. j av a2 s. c om */ static public void delete(String repoName) { try { Mongo mDel = new Mongo(); mDel.dropDatabase(repoName); mDel.close(); } catch (UnknownHostException e) { throw new RuntimeException(e); } catch (MongoException e) { throw new RuntimeException(e); } }
From source file:net.vz.mongodb.jackson.MongoDBTestBase.java
License:Apache License
@Before public void connectToDb() throws Exception { mongo = new Mongo(); db = mongo.getDB("unittest"); collections = new HashSet<String>(); }
From source file:org.apache.isis.objectstore.nosql.db.mongo.DemoMongo.java
License:Apache License
public void installed() throws Exception { final Mongo m = new Mongo(); for (final String s : m.getDatabaseNames()) { System.out.println(s);/*from w w w. j a v a 2s . c o m*/ } /* * Mongo m = new Mongo( "localhost" ); Mongo m = new Mongo( "localhost" * , 27017 ); */ m.dropDatabase("mydb"); System.out.println("\n..."); for (final String s : m.getDatabaseNames()) { System.out.println(s); } final DB db = m.getDB("mydb"); /* * DBCollection coll = db.getCollection("testCollection1"); coll = * db.getCollection("testCollection2"); */ final DBCollection coll = db.getCollection("testCollection1"); final BasicDBObject doc = new BasicDBObject(); doc.put("name", "MongoDB"); doc.put("type", "database"); doc.put("count", 1); final BasicDBObject info = new BasicDBObject(); info.put("x", 203); info.put("y", 102); doc.put("info", info); coll.insert(doc); final Set<String> colls = db.getCollectionNames(); for (final String s : colls) { System.out.println(s); } }
From source file:org.apache.metamodel.mongodb.mongo2.MongoDbDataCopyer.java
License:Apache License
public static void main(String[] args) throws Exception { System.setProperty("derby.storage.tempDirector", FileHelper.getTempDir().getAbsolutePath()); System.setProperty("derby.stream.error.file", File.createTempFile("metamodel-derby", ".log").getAbsolutePath()); File dbFile = new File("../jdbc/src/test/resources/derby_testdb.jar"); dbFile = dbFile.getCanonicalFile();/* ww w. java2s . c o m*/ if (!dbFile.exists()) { throw new IllegalStateException("File does not exist: " + dbFile); } Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); Connection connection = DriverManager .getConnection("jdbc:derby:jar:(" + dbFile.getAbsolutePath() + ")derby_testdb;territory=en"); connection.setReadOnly(true); DB db = new Mongo().getDB("orderdb_copy"); DataContext sourceDataContext = new JdbcDataContext(connection); new MongoDbDataCopyer(db, "orders", sourceDataContext, "APP", "orders").copy(); new MongoDbDataCopyer(db, "offices", sourceDataContext, "APP", "offices").copy(); new MongoDbDataCopyer(db, "payments", sourceDataContext, "APP", "payments").copy(); new MongoDbDataCopyer(db, "orderfact", sourceDataContext, "APP", "orderfact").copy(); new MongoDbDataCopyer(db, "products", sourceDataContext, "APP", "products").copy(); connection.close(); }
From source file:org.eclipse.jetty.nosql.mongodb.MongoSessionIdManager.java
License:Open Source License
public MongoSessionIdManager(Server server) throws UnknownHostException, MongoException { this(server, new Mongo().getDB("HttpSessions").getCollection("sessions")); }
From source file:org.eclipse.jetty.nosql.mongodb.MongoSessionStoreFactory.java
License:Open Source License
/** * @throws MongoException // ww w .j a v a 2 s.c om * @throws UnknownHostException * @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(org.eclipse.jetty.server.session.SessionHandler) */ @Override public SessionStore getSessionStore(SessionHandler handler) throws Exception { MongoSessionStore store = new MongoSessionStore(); store.setGracePeriodSec(getGracePeriodSec()); store.setDBCollection(new Mongo().getDB(getDbName()).getCollection(getCollectionName())); return store; }
From source file:org.eclipse.jetty.nosql.mongodb.MongoTestHelper.java
License:Open Source License
public static void dropCollection() throws MongoException, UnknownHostException { new Mongo().getDB(DB_NAME).getCollection(COLLECTION_NAME).drop(); }
From source file:org.eclipse.jetty.nosql.mongodb.MongoTestHelper.java
License:Open Source License
public static void createCollection() throws UnknownHostException, MongoException { new Mongo().getDB(DB_NAME).createCollection(COLLECTION_NAME, null); }
From source file:org.eclipse.jetty.nosql.mongodb.MongoTestHelper.java
License:Open Source License
public static DBCollection getCollection() throws UnknownHostException, MongoException { return new Mongo().getDB(DB_NAME).getCollection(COLLECTION_NAME); }
From source file:org.einherjer.week2.samples.DotNotationSample.java
License:Apache License
public static void main(String[] args) throws UnknownHostException { Mongo client = new Mongo(); DB db = client.getDB("course"); DBCollection lines = db.getCollection("dotNotationSample"); lines.drop();//from w w w. j a v a2s.com Random rand = new Random(); // insert 10 lines with random start and end points for (int i = 0; i < 10; i++) { lines.insert( new BasicDBObject("_id", i) .append("start", new BasicDBObject("x", rand.nextInt(90) + 10).append("y", rand.nextInt(90) + 10)) .append("end", new BasicDBObject("x", rand.nextInt(90) + 10).append("y", rand.nextInt(90) + 10))); } QueryBuilder builder = QueryBuilder.start("start.x").greaterThan(50); DBCursor cursor = lines.find(builder.get(), new BasicDBObject("start.y", true).append("_id", false)); try { while (cursor.hasNext()) { DBObject cur = cursor.next(); System.out.println(cur); } } finally { cursor.close(); } }