Refine search
Mongo mongo = PowerMockito.mock(Mongo.class); DB db = PowerMockito.mock(DB.class); DBCollection dbCollection = PowerMockito.mock(DBCollection.class); PowerMockito.when(mongo.getDB("foo")).thenReturn(db); PowerMockito.when(db.getCollection("bar")).thenReturn(dbCollection); MyService svc = new MyService(mongo); // Use some kind of dependency injection svc.getObjectById(1); PowerMockito.verify(dbCollection).findOne(new BasicDBObject("_id", 1));
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()); } }
MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mydb"); DBCollection myCollection = db.getCollection("myCollection"); myCollection.drop();
@Inject public DBCacheService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, ClusterEventBus clusterEventBus) { this.db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection("lut_caches"), CacheDto.class, ObjectId.class, mapper.get()); this.clusterEventBus = clusterEventBus; db.createIndex(new BasicDBObject("name", 1), new BasicDBObject("unique", true)); }
new ServerAddress(this.config.net().getServerAddress() .getHostName(), this.config.net().getPort()), options)) { DB mongoAdminDB = mongo.getDB(ADMIN_DATABASE_NAME); cr = mongoAdminDB.command(new BasicDBObject("addShard", command)); logger.info(cr.toString()); cr = mongoAdminDB.command(new BasicDBObject("listShards", 1)); logger.info(cr.toString()); cr = mongoAdminDB.command(new BasicDBObject("enableSharding", this.shardDatabase)); logger.info(cr.toString()); 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();
database = mongo.getDB(dbname); collection = database.getCollection(collectionName);
@Inject public DBLookupTableService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, ClusterEventBus clusterEventBus) { this.db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection("lut_tables"), LookupTableDto.class, ObjectId.class, mapper.get()); this.clusterEventBus = clusterEventBus; db.createIndex(new BasicDBObject("name", 1), new BasicDBObject("unique", true)); }
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()); }
DB db = mongo.getDB(databaseName); db.getCollection(tableInfo.getTableName()).drop(); if (db.collectionExists(tableInfo.getTableName() + MongoDBUtils.FILES)) db.getCollection(tableInfo.getTableName() + MongoDBUtils.FILES).drop(); KunderaCoreUtils.printQuery( "Drop existing Grid FS Metadata collection: " + tableInfo.getTableName() db.getCollection(tableInfo.getTableName() + MongoDBUtils.CHUNKS).drop(); KunderaCoreUtils.printQuery("Drop existing Grid FS data collection: " + tableInfo.getTableName() + MongoDBUtils.CHUNKS, showQuery);
@Inject public TrafficCounterService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper) { db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection("traffic"), TrafficDto.class, ObjectId.class, mapper.get()); db.createIndex(new BasicDBObject(BUCKET, 1), new BasicDBObject("unique", 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)); }
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);
@Inject public DBDataAdapterService(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapper, ClusterEventBus clusterEventBus) { this.db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection("lut_data_adapters"), DataAdapterDto.class, ObjectId.class, mapper.get()); this.clusterEventBus = clusterEventBus; db.createIndex(new BasicDBObject("name", 1), new BasicDBObject("unique", true)); }
MongoClient mongo = new MongoClient(new ServerAddress("localhost", 27017)); DB db = mongo.getDB("thedb"); DBCollection collection = db.getCollection("test"); BasicDBObject query = new BasicDBObject(); query.append("age", 25); collection.remove(query);
DB db = mongo.getDB(databaseName); DBCollection collection = null; if (tableInfo.getLobColumnInfo().isEmpty()) collection = collection != null ? collection : db.getCollection(tableInfo.getTableName());
@Inject public IndexFieldTypesService(MongoConnection mongoConnection, MongoJackObjectMapperProvider objectMapperProvider) { this.db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection("index_field_types"), IndexFieldTypesDTO.class, ObjectId.class, objectMapperProvider.get()); this.db.createIndex(new BasicDBObject(ImmutableMap.of( IndexFieldTypesDTO.FIELD_INDEX_NAME, 1, IndexFieldTypesDTO.FIELD_INDEX_SET_ID, 1 )), new BasicDBObject("unique", true)); this.db.createIndex(new BasicDBObject(IndexFieldTypesDTO.FIELD_INDEX_NAME, 1), new BasicDBObject("unique", true)); this.db.createIndex(new BasicDBObject(FIELDS_FIELD_NAMES, 1)); }
public DBCollection openMongoDb() throws UnknownHostException { MongoClientURI dbUri = new MongoClientURI(dbUriStr_+"?socketTimeoutMS=180000"); mongoClient_ = new MongoClient(dbUri); DB db = mongoClient_.getDB( dbName_ ); DBCollection coll = db.getCollection(collection_); coll.createIndex(new BasicDBObject(index_, 1)); // create index on "i", ascending return coll; }
public static DBCollection getCollection(final MongoClientURI uri) { try { return new MongoClient(uri).getDB(uri.getDatabase()).getCollection(uri.getCollection()); } catch (Exception e) { throw new IllegalArgumentException("Couldn't connect and authenticate to get collection", e); } }
@Inject public AlertServiceImpl(MongoConnection mongoConnection, MongoJackObjectMapperProvider mapperProvider, AlertConditionFactory alertConditionFactory, AlarmCallbackHistoryService alarmCallbackHistoryService) { this.alertConditionFactory = alertConditionFactory; this.alarmCallbackHistoryService = alarmCallbackHistoryService; final String collectionName = AlertImpl.class.getAnnotation(CollectionName.class).value(); final DBCollection dbCollection = mongoConnection.getDatabase().getCollection(collectionName); dbCollection.createIndex(new BasicDBObject(ImmutableMap.of( AlertImpl.FIELD_TRIGGERED_AT, -1, AlertImpl.FIELD_STREAM_ID, 1 ))); this.coll = JacksonDBCollection.wrap(dbCollection, AlertImpl.class, String.class, mapperProvider.get()); }
MongoClient mongo = new MongoClient ("localhost", 27017); DB db = mongo.getDB("DBHC2"); DBCollection movieDocument = db.getCollection("movies"); BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("rateMovies.idMovie", idMovie); DBCursor cursor = movieDocument.find(searchQuery);