Refine search
private Timestamp<?> getCurrentOplogTimestamp(MongoClient shardClient) { DBCollection oplogCollection = shardClient .getDB(MongoDBRiver.MONGODB_LOCAL_DATABASE) .getCollection(MongoDBRiver.OPLOG_COLLECTION); try (DBCursor cursor = oplogCollection.find().sort(new BasicDBObject("$natural", -1)).limit(1)) { return Timestamp.on(cursor.next()); } }
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();
/** * 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()); } }
MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mydb"); DBCollection myCollection = db.getCollection("myCollection"); myCollection.drop();
.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);
public OplogSlurper(MongoDBRiver river, Timestamp<?> timestamp, MongoClient mongoClusterClient, MongoClient mongoShardClient) { super(river); this.river = river; this.timestamp = timestamp; this.definition = river.definition; this.context = river.context; this.esClient = river.esClient; this.mongoClusterClient = mongoClusterClient; this.mongoShardClient = mongoShardClient; this.findKeys = new BasicDBObject(); this.gridfsOplogNamespace = definition.getMongoOplogNamespace() + MongoDBRiver.GRIDFS_FILES_SUFFIX; this.cmdOplogNamespace = definition.getMongoDb() + "." + MongoDBRiver.OPLOG_NAMESPACE_COMMAND; if (definition.getExcludeFields() != null) { for (String key : definition.getExcludeFields()) { findKeys.put(key, 0); } } else if (definition.getIncludeFields() != null) { for (String key : definition.getIncludeFields()) { findKeys.put(key, 1); } } this.oplogDb = mongoShardClient.getDB(MongoDBRiver.MONGODB_LOCAL_DATABASE); this.oplogCollection = oplogDb.getCollection(MongoDBRiver.OPLOG_COLLECTION); this.oplogRefsCollection = oplogDb.getCollection(MongoDBRiver.OPLOG_REFS_COLLECTION); this.slurpedDb = mongoShardClient.getDB(definition.getMongoDb()); }
MongoClient m = new MongoClient(new ServerAddress("localhost", 27017), Arrays.asList(credential)); DB db = m.getDB(dbname); DB db_admin = m.getDB(adminDb);
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)); }
mongo = new MongoClient(addr, credentials); db = mongo.getDB(databaseName); return true;
/** {@inheritDoc} */ @Override public void createSchema() { if (!mongoClient.getDB(dbName).collectionExists(collectionName)) { BasicDBObject options = new BasicDBObject(); options.put("size", 10000); mongoClient.getDB(dbName).createCollection(collectionName, options); } propertiesCollection = mongoClient.getDB(dbName).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()); } }
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);
private static void dropDB() throws UnknownHostException { MongoClient mongoClient = new MongoClient(new ServerAddress("localhost", 27017)); DB db = mongoClient.getDB("sparktest"); db.dropDatabase(); }
/** {@inheritDoc} */ @Override public void createSchema() { if (!mongoClient.getDB(dbName).collectionExists(collectionName)) { BasicDBObject options = new BasicDBObject(); options.put("size", 10000); featuresCollection = mongoClient.getDB(dbName).createCollection(collectionName, options); } featuresCollection = mongoClient.getDB(dbName).getCollection(collectionName); }
password.toCharArray()); MongoClient m = new MongoClient(new ServerAddress("localhost", 27017), Arrays.asList(credential)); DB db = m.getDB(dbname); collectionList = db.getCollectionNames();
MongoClient mongoClient = new MongoClient( "localhost" , 27017 ); DB db = mongoClient.getDB("databaseName"); DBCollection coll = db.getCollection("my.collection"); JacksonDBCollection<MyDomainObject, String> wrapped = JacksonDBCollection.wrap(coll, MyDomainObject.class, String.class);
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)));
/** * Creates a new {@link MongoParentMetadataRepository} * @param client - The client connection to mongo. * @param dbName - The database to connect to, usually the RyaInstanceName */ public MongoParentMetadataRepository(final MongoClient client, final String dbName) { checkNotNull(client); checkNotNull(dbName); collection = client.getDB(dbName).getCollection(COLLECTION_NAME); adapter = new ParentMetadataRepositoryAdapter(); }
@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); }