本文整理汇总了Java中com.mongodb.rx.client.MongoClients类的典型用法代码示例。如果您正苦于以下问题:Java MongoClients类的具体用法?Java MongoClients怎么用?Java MongoClients使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoClients类属于com.mongodb.rx.client包,在下文中一共展示了MongoClients类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: SimpleMongoAsyncTest
import com.mongodb.rx.client.MongoClients; //导入依赖的package包/类
public SimpleMongoAsyncTest() throws IOException {
// Start embeded mongo
config = new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
.net(new Net(27018, Network.localhostIsIPv6()))
.build();
exe = MongodStarter.getDefaultInstance().prepare(config);
mongoProcess = exe.start();
AtomicBoolean started = new AtomicBoolean(false);
// Start mongo client
client = MongoClients.create("mongodb://localhost:27018");
database = client.getDatabase("test");
collection = database.getCollection(COLLECTION_NAME);
morphia = new Morphia().mapPackage("com.querydsl.mongodb.domain");
}
开发者ID:egopulse,项目名称:querydsl-mongodb-async,代码行数:19,代码来源:SimpleMongoAsyncTest.java
示例2: populate
import com.mongodb.rx.client.MongoClients; //导入依赖的package包/类
@Test
public void populate() {
int simulationCount = 1;
MongoClient mongoClient = MongoClients.create("mongodb://localhost:27017");
MongoDatabase database = mongoClient.getDatabase(databaseName);
MongoCollection<Document> collection = database.getCollection(sample);
for (int i = 0; i < simulationCount; i++) {
Document d = new Document("name", "Person " + i).append("updatedAt", new Date());
collection.insertOne(d).toList().toBlocking().single();
}
}
开发者ID:glytching,项目名称:dragoman,代码行数:15,代码来源:MongoPopulatorTool.java
示例3: MongoSongStore
import com.mongodb.rx.client.MongoClients; //导入依赖的package包/类
public MongoSongStore() {
String connectionString = System.getProperty(CONNECTION_STRING_PROPERTY, "mongodb://localhost");
String databaseName = System.getProperty(DATABASE_NAME_PROPERTY, "default");
String collectionName = System.getProperty(COLLECTION_NAME_PROPERTY, "default");
mongoClient = MongoClients.create(new ConnectionString(connectionString));
mongoDatabase = mongoClient.getDatabase(databaseName);
mongoCollection = mongoDatabase.getCollection(collectionName);
logger.info("Initialized Mongo Driver with databaseName=" + databaseName + " collectionName=" + collectionName);
}
开发者ID:alexandrubordei,项目名称:goomusic,代码行数:13,代码来源:MongoSongStore.java
示例4: startImport
import com.mongodb.rx.client.MongoClients; //导入依赖的package包/类
@Override
public Observable<Document> startImport() {
MongoClient client = MongoClients.create(connectionString);
MongoDatabase db = client.getDatabase(dbName);
return db.getCollection(collectionName).find().toObservable()
.map(new Func1<org.bson.Document, Document>() {
public Document call(org.bson.Document mongoDoc) {
mongoDoc.put(typeField, type);
RawJsonDocument d = RawJsonDocument.create(mongoDoc
.getObjectId("_id").toHexString(), mongoDoc
.toJson());
return d;
};
});
}
开发者ID:ldoguin,项目名称:couchbase-java-importer,代码行数:16,代码来源:MongoDBConfig.java
示例5: createMongoClient
import com.mongodb.rx.client.MongoClients; //导入依赖的package包/类
/**
* Lazily instantiate the {@link MongoClient} instance.
*
* @return
*/
private MongoClient createMongoClient() {
String host = applicationConfiguration.getMongoHost();
int port = applicationConfiguration.getMongoPort();
ConnectionString connectionString = new ConnectionString("mongodb://" + host + ":" + port);
logger.info("Creating Mongo client for: {}:{}", host, port);
MongoClientSettings mongoClientSettings =
MongoClientSettings.builder()
.applicationName("dragoman")
.serverSettings(
ServerSettings.builder()
.applyConnectionString(connectionString)
.addServerMonitorListener(new LoggingServerMonitorListener())
.addServerListener(new LoggingServerListener())
.build())
.clusterSettings(
ClusterSettings.builder()
.applyConnectionString(connectionString)
.serverSelectionTimeout(
applicationConfiguration.getMongoServerSelectionTimeout(), MILLISECONDS)
.addClusterListener(new LoggingClusterListener())
.build())
.connectionPoolSettings(
ConnectionPoolSettings.builder()
.applyConnectionString(connectionString)
.maxWaitTime(
applicationConfiguration.getConnectionPoolMaxWaitTime(), MILLISECONDS)
.minSize(applicationConfiguration.getConnectionPoolMinSize())
.maxSize(applicationConfiguration.getConnectionPoolMaxSize())
.addConnectionPoolListener(new LoggingConnectionPoolListener())
.build())
.socketSettings(
SocketSettings.builder()
.applyConnectionString(connectionString)
.connectTimeout(
applicationConfiguration.getMongoSocketConnectionTimeout(), MILLISECONDS)
.readTimeout(applicationConfiguration.getMongoReadTimeout(), MILLISECONDS)
.build())
.build();
return MongoClients.create(mongoClientSettings);
}
开发者ID:glytching,项目名称:dragoman,代码行数:49,代码来源:MongoProviderImpl.java
示例6: getMongoClient
import com.mongodb.rx.client.MongoClients; //导入依赖的package包/类
protected MongoClient getMongoClient() {
if (mongoClient == null) {
mongoClient = MongoClients.create("mongodb://localhost:" + port);
}
return mongoClient;
}
开发者ID:glytching,项目名称:dragoman,代码行数:7,代码来源:AbstractMongoDBTest.java
示例7: configure
import com.mongodb.rx.client.MongoClients; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
/** connection string */
ConnectionString cstr = Try.apply(() -> new ConnectionString(db))
.orElseGet(() -> new ConnectionString(conf.getString(db)));
log.debug("Starting {}", cstr);
boolean first = instances.getAndIncrement() == 0;
Throwing.Function3<Class, String, Object, Void> bind = (type, name, value) -> {
binder.bind(Key.get(type, Names.named(name))).toInstance(value);
if (first) {
binder.bind(Key.get(type)).toInstance(value);
}
return null;
};
/** settings */
MongoClientSettings.Builder settings = settings(cstr, dbconf(db, conf));
if (configurer != null) {
configurer.accept(settings, conf);
}
MongoClient client = MongoClients.create(settings.build());
bind.apply(MongoClient.class, db, client);
/** bind database */
Optional.ofNullable(cstr.getDatabase()).ifPresent(dbname -> {
// observable adapter
MongoDatabase predb = adapter
.map(a -> client.getDatabase(dbname).withObservableAdapter(a))
.orElseGet(() -> client.getDatabase(dbname));
// codec registry
MongoDatabase database = codecRegistry
.map(predb::withCodecRegistry)
.orElse(predb);
bind.apply(MongoDatabase.class, dbname, database);
/** bind collection */
Optional.ofNullable(cstr.getCollection()).ifPresent(cname -> {
MongoCollection<Document> collection = database.getCollection(cname);
bind.apply(MongoCollection.class, cname, collection);
});
});
/** mapper */
env.router()
.map(mapper());
log.info("Started {}", cstr);
env.onStop(() -> {
log.debug("Stopping {}", cstr);
client.close();
log.info("Stopped {}", cstr);
});
}
开发者ID:jooby-project,项目名称:jooby,代码行数:59,代码来源:MongoRx.java
注:本文中的com.mongodb.rx.client.MongoClients类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论