Refine search
m = new MongoClient(mongoClientURI); db = m.getDB(dbName); db.setWriteConcern(WriteConcern.ACKNOWLEDGED); final Version mongoVersion = getMongoVersion(m.getDB("admin")); if (mongoVersion != null && mongoVersion.lessThan(MINIMUM_MONGODB_VERSION)) { LOG.warn("You're running MongoDB {} but Graylog requires at least MongoDB {}. Please upgrade.",
.connectTimeout(10) .build(); try (MongoClient mongo = new MongoClient( new ServerAddress(this.config.net().getServerAddress() .getHostName(), this.config.net().getPort()), options)) { DB mongoAdminDB = mongo.getDB(ADMIN_DATABASE_NAME); DB db = mongo.getDB(this.shardDatabase); db.getCollection(this.shardCollection).createIndex(this.shardKey); DBCursor cursor = mongo.getDB("config").getCollection("shards").find(); while (cursor.hasNext()) { DBObject item = cursor.next();
.connectTimeout(10) .build(); MongoClient mongo = new MongoClient(new ServerAddress(mongoConfigList.get(0).net() .getServerAddress().getHostName(), mongoConfigList.get(0).net() .getPort()), mo); DB mongoAdminDB = mongo.getDB(ADMIN_DATABASE_NAME);
MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mydb"); DBCollection myCollection = db.getCollection("myCollection"); myCollection.drop();
mongo = new MongoClient(addr, credentials); db = mongo.getDB(databaseName); return true;
public MongoSchemaDBStore(MongoClientURI uri) throws IOException { client = new MongoClient(uri); String databaseName = uri.getDatabase(); if (databaseName == null) { databaseName = DEFAULT_databaseName; } DB database = client.getDB(databaseName); String collectionName = uri.getCollection(); if (collectionName == null) { collectionName = DEFAULT_collectionName; } collection = database.getCollection(collectionName); collection.createIndex( new BasicDBObject(FeatureTypeDBObject.KEY_typeName, 1), new BasicDBObject("unique", true)); }
private static void dropDB() throws UnknownHostException { MongoClient mongoClient = new MongoClient(new ServerAddress("localhost", 27017)); DB db = mongoClient.getDB("sparktest"); db.dropDatabase(); }
/** * No authentication test. * */ // @Test public void noAuthenticationTest() { try { _PU = "mongoTest"; String dbname = "KunderaAuthTests"; MongoClient m = new MongoClient(new ServerAddress("localhost", 27017)); DB db = m.getDB(dbname); Assert.assertNotNull(db.getCollectionNames()); emf = Persistence.createEntityManagerFactory(_PU); Assert.assertNotNull(emf); EntityManager em = emf.createEntityManager(); Assert.assertNotNull(em); } catch (Exception e) { Assert.fail(e.getMessage()); } }
verifyProperty(password, "password"); mongo = new MongoClient( new ServerAddress(mongouri, port), Arrays.asList(MongoCredential.createMongoCRCredential(username, dbname, password.toCharArray())) verifyProperty(password, "password"); mongo = new MongoClient( new ServerAddress(mongouri, port), Arrays.asList(MongoCredential.createMongoCRCredential(username, AUTH_ON_ADMIN, password.toCharArray())) mongo = new MongoClient(new ServerAddress(mongouri, port)); database = mongo.getDB(dbname); collection = database.getCollection(collectionName);
/** * Authenticate with valid credentials * * */ // @Test public void authenticateWithValidCredentials() { try { _PU = "validAuthenticationMongoPu"; String dbname = "KunderaAuthTests"; String username = "kunderaUser"; String password = "kunderapassword"; MongoCredential credential = MongoCredential.createMongoCRCredential(username, dbname, password.toCharArray()); MongoClient m = new MongoClient(new ServerAddress("localhost", 27017), Arrays.asList(credential)); DB db = m.getDB(dbname); Assert.assertNotNull(db.getCollectionNames()); m.close(); emf = Persistence.createEntityManagerFactory(_PU); Assert.assertNotNull(emf); EntityManager em = emf.createEntityManager(); Assert.assertNotNull(em); } catch (Exception e) { Assert.fail(e.getMessage()); } }
password.toCharArray()); MongoClient m = new MongoClient(new ServerAddress("localhost", 27017), Arrays.asList(credential)); DB db = m.getDB(dbname); collectionList = db.getCollectionNames();
MongoClient m = new MongoClient(new ServerAddress("localhost", 27017), Arrays.asList(credential)); DB db = m.getDB(dbname); DB db_admin = m.getDB(adminDb);
final MongoClient mongoClient = new MongoClient(); final DBCollection coll = mongoClient.getDB("TheDatabase").getCollection("TheCollection"); coll.update(<query>, new BasicDBObject("$push", new BasicDBObject(<field>, new BasicDBObject("$each", new BasicDBList() .put(0,<value1>) .put(1,<value2>) .put(3,<value3>)) .append('$slice',-5)));
@SuppressWarnings("deprecation") private void initialize() throws UnknownHostException { ServerAddress dbAddress = new ServerAddress("synat2.vls.icm.edu.pl", 27018); connection = new MongoClient(dbAddress); collection = connection.getDB(dbName).getCollection(collectionName); }
@SuppressWarnings("deprecation") private void initialize() throws UnknownHostException { ServerAddress dbAddress = new ServerAddress("synat2.vls.icm.edu.pl", 27018); connection = new MongoClient(dbAddress); collection = connection.getDB(dbName).getCollection(collectionName); }
MongoClient mongoClient = new MongoClient("127.0.34.1", 89); DB db = mongoClient.getDB("test"); try { db.addUser("user", new char[] {'p', 'a', 's', 's'}); } catch(Exception e) { MongoTimeoutException exception}
// set up pipeline List<DBObject> ops = new ArrayList<DBObject>(); ops.add(new BasicDBObject("$out", "target")); // writes to collection "target" // run it MongoClient client = new MongoClient("host"); DBCollection source = client.getDB("db").getCollection("source") source.aggregate(ops);
@SuppressWarnings("deprecation") public YExportableIterator(String host, int port, String dbName, String collectionName) throws UnknownHostException { ServerAddress dbAddress = new ServerAddress(host, port); connection = new MongoClient(dbAddress); collection = connection.getDB(dbName).getCollection(collectionName); }
DB connectToMongoAndGetDatabase() throws MojoExecutionException { if (databaseName == null || databaseName.trim().length() == 0) { throw new MojoExecutionException("Database name is missing"); } MongoClient mongoClient = new MongoClient("localhost", getPort()); getLog().info("Connected to MongoDB"); return mongoClient.getDB(databaseName); } }
MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("test"); DBCollection coll = db.getCollection("testcol"); LocalDate ld = LocalDate.now(); Instant instant = ld.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(); Date date = Date.from(instant); BasicDBObject doc = new BasicDBObject("localdate", date); coll.insert(doc);