本文整理汇总了Java中com.mongodb.QueryBuilder.greaterThanEquals方法的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder.greaterThanEquals方法的具体用法?Java QueryBuilder.greaterThanEquals怎么用?Java QueryBuilder.greaterThanEquals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder.greaterThanEquals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendToBuilder
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
protected QueryBuilder appendToBuilder(final QueryBuilder builder,
final FilterOp filterOp, final List<Object> rawOperands) {
List<String> operands = convertOperandsToString(rawOperands);
switch (filterOp) {
case EQUALS:
if (operands.size() == 1) {
builder.is(operands.iterator().next());
} else {
builder.in(operands);
}
break;
case NOT_EQUALS:
if (operands.size() == 1) {
builder.notEquals(operands.iterator().next());
} else {
builder.notIn(operands);
}
break;
case LESS:
builder.lessThan(operands);
break;
case LESS_OR_EQUAL:
builder.lessThanEquals(operands);
break;
case GREATER:
builder.greaterThan(operands);
break;
case GREATER_OR_EQUAL:
builder.greaterThanEquals(operands);
break;
default:
throw new IllegalArgumentException(filterOp
+ " no MongoDB equivalent yet");
}
return builder;
}
示例2: manyChildNodes
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
@Test
@Ignore
public void manyChildNodes() {
DB db = MongoUtils.getConnection().getDB();
MongoUtils.dropCollections(db);
DBCollection nodes = db.getCollection(Collection.NODES.toString());
DBObject index = new BasicDBObject();
// modification time (descending)
index.put("_mod", -1L);
// and then id (ascending)
index.put("_id", 1L);
DBObject options = new BasicDBObject();
// options.put("unique", Boolean.TRUE);
nodes.ensureIndex(index, options);
// index on (_id, _mod):
// Query plan: { "cursor" : "BtreeCursor _id_1__mod_-1" ,
// "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 ,
// "nscanned" : 954647 , "nscannedObjectsAllPlans" : 1907080 ,
// "nscannedAllPlans" : 2859727 , "scanAndOrder" : false ,
// "indexOnly" : true , "nYields" : 5 , "nChunkSkips" : 0 ,
// "millis" : 5112 ,...
// Time: 2229 ms
// Count: 2000
// index on (_mod, _id)
// Query plan: { "cursor" : "BtreeCursor _mod_-1__id_1" ,
// "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 ,
// "nscanned" : 2000 , "nscannedObjectsAllPlans" : 2203 ,
// "nscannedAllPlans" : 2203 , "scanAndOrder" : false ,
// "indexOnly" : true , "nYields" : 0 , "nChunkSkips" : 0 ,
// "millis" : 3 ,...
// Time: 43 ms
// Count: 2000
int children = 1000000;
int perInsert = 1000;
int group = 0;
String parent = "/parent/node/abc";
for (int i = 0; i < children;) {
DBObject[] inserts = new DBObject[perInsert];
group++;
for (int j = 0; j < perInsert; j++, i++) {
BasicDBObject doc = new BasicDBObject();
inserts[j] = doc;
doc.put("_id", parent + "/node" + i);
doc.put("_mod", group);
}
nodes.insert(inserts, WriteConcern.SAFE);
log("inserted " + i + "/" + children);
}
QueryBuilder queryBuilder = QueryBuilder.start("_mod");
queryBuilder.greaterThanEquals(group - 1);
queryBuilder.and("_id").greaterThan(parent + "/");
queryBuilder.and("_id").lessThanEquals(parent + "0");
DBObject query = queryBuilder.get();
BasicDBObject keys = new BasicDBObject();
keys.put("_id", 1);
DBCursor cursor = nodes.find(query, keys);
int count = 0;
log("Query plan: " + cursor.explain());
long time = System.currentTimeMillis();
while (cursor.hasNext()) {
DBObject obj = cursor.next();
// dummy read operation (to ensure we did get the data)
obj.get("_id");
count++;
// log(" read " + obj);
}
time = System.currentTimeMillis() - time;
log("Time: " + time + " ms");
log("Count: " + count);
db.getMongo().close();
}
示例3: calculateSplits
import com.mongodb.QueryBuilder; //导入方法依赖的package包/类
/**
* Calculate splits.
*
* @param collection the collection
* @return the deep partition [ ]
*/
private DeepPartition[] calculateSplits(DBCollection collection) {
BasicDBList splitData = getSplitData(collection);
List<ServerAddress> serverAddressList = collection.getDB().getMongo().getServerAddressList();
if (splitData == null) {
Pair<BasicDBList, List<ServerAddress>> pair = getSplitDataCollectionShardEnviroment(getShards(collection),
collection.getDB().getName(),
collection.getName());
splitData = pair.left;
serverAddressList = pair.right;
}
Object lastKey = null; // Lower boundary of the first min split
List<String> stringHosts = new ArrayList<>();
for (ServerAddress serverAddress : serverAddressList) {
stringHosts.add(serverAddress.toString());
}
int i = 0;
MongoPartition[] partitions = new MongoPartition[splitData.size() + 1];
for (Object aSplitData : splitData) {
BasicDBObject currentKey = (BasicDBObject) aSplitData;
Object currentO = currentKey.get(MONGO_DEFAULT_ID);
partitions[i] = new MongoPartition(mongoDeepJobConfig.getRddId(), i, new DeepTokenRange(lastKey,
currentO, stringHosts), MONGO_DEFAULT_ID);
lastKey = currentO;
i++;
}
QueryBuilder queryBuilder = QueryBuilder.start(MONGO_DEFAULT_ID);
queryBuilder.greaterThanEquals(lastKey);
partitions[i] = new MongoPartition(0, i, new DeepTokenRange(lastKey, null, stringHosts), MONGO_DEFAULT_ID);
return partitions;
}