java 调用mongo 判断大于等于 并且小约等于<=

房东的猫 提交于 2020-02-26 17:59:45
初始化mongo链接

MongoClientOptions options = new Builder().connectionsPerHost(300).connectTimeout(20000)
.maxConnectionIdleTime(60000).maxWaitTime(1000 * 60 * 2).socketKeepAlive(true).socketTimeout(60000)
.threadsAllowedToBlockForConnectionMultiplier(50).build();
MongoCredential credential = MongoCredential.createCredential("foest", "markett",
"123456".toCharArray());
ServerAddress serverAddress = new ServerAddress("192.1.15.19", 20000);
MongoClient mongoClient = new MongoClient(serverAddress, credential, options);
database = mongoClient.getDatabase("market-data-forex-test");
kLineCollection = database.getCollection("KLine");

封装查询条件:

BasicDBObject query = new BasicDBObject();
 query.append("code", "CU00");
query.append("period", 1);
query.put("barTime", new BasicDBObject("$gte", 20171127210100L).append("$lt", 20171127210200L));
//查询该条件下数据的数量
long klineAmount = kLineCollection.countDocuments(query);

 

 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!