• 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<MongoCredential> credentials = new ArrayList<MongoCredential>(); credentials.add(credential); //3.mongodb服务器相关配置 List<ServerAddress> addresses=new ArrayList<ServerAddress>(); 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()); }

    2020-03-12
    50
上传资源赚积分or赚钱