-
mongo-java-driver最新jar.zip下载
资源介绍
mongo-java-driver3.0以上jar压缩包大全
try {
//1.连接池相关选项配置
MongoClientOptions options=MongoClientOptions.builder()
.connectionsPerHost(poolSize)
.minConnectionsPerHost(minpoolsize)
.maxConnectionIdleTime(maxidletimems)
.threadsAllowedToBlockForConnectionMultiplier(blockSize)
.maxWaitTime(maxWaitTime)
.socketTimeout(socketTimeout)
.connectTimeout(connectTimeout)
.build();
//2.鉴权配置
MongoCredential credential = MongoCredential.createScramSha1Credential(uname, "admin", pwd.toCharArray());
List credentials = new ArrayList();
credentials.add(credential);
//3.mongodb服务器相关配置
List addresses=new ArrayList();
addresses.add(new ServerAddress(host, port));
//4.创建客户实例,获取数据库存储对象。
MongoClient mongoClient = new MongoClient(addresses,credentials, options);
morphia.mapPackage("com.lolaage");// 告诉morphia到哪个包下面去找实体类
logger.warn("获取数据库连接对象>>>>>>>>>>>>>>>>>");
ds = morphia.createDatastore(mongoClient, databaseName);// 构建Datastore对象,其中`databaseName`是数据库名称
ds.ensureIndexes();//确保索引生效
//} catch (UnknownHostException e) {
// logger.error(e.getMessage());
}
- 上一篇: Java断点续传
- 下一篇: sukkiri-java-v2-chap06-list06-calc