本文整理汇总了Java中com.mongodb.AggregationOptions类的典型用法代码示例。如果您正苦于以下问题:Java AggregationOptions类的具体用法?Java AggregationOptions怎么用?Java AggregationOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AggregationOptions类属于com.mongodb包,在下文中一共展示了AggregationOptions类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWithOptions
import com.mongodb.AggregationOptions; //导入依赖的package包/类
/**
* Do aggregation with options.
*/
//@Test
public void testWithOptions(){
connectDB();
BookDao dao = new BookDao();
Iterable<DBObject> it = dao.aggregate()
.setOptions(AggregationOptions.builder().allowDiskUse(Boolean.TRUE).build())
.sort("{price : -1}")
.results();
for(DBObject dbo : it){
System.out.println(dbo.get("price"));
}
disconnectDB();
}
示例2: testOut
import com.mongodb.AggregationOptions; //导入依赖的package包/类
@Test
public void testOut() {
checkMinServerVersion(2.6);
getDs().save(asList(new Book("The Banquet", "Dante", 2),
new Book("Divine Comedy", "Dante", 1),
new Book("Eclogues", "Dante", 2),
new Book("The Odyssey", "Homer", 10),
new Book("Iliad", "Homer", 10)));
AggregationOptions options = builder()
.build();
Iterator<Author> aggregate = getDs().createAggregation(Book.class)
.group("author", grouping("books", push("title")))
.out(Author.class, options);
Assert.assertEquals(2, getDs().getCollection(Author.class).count());
Author author = aggregate.next();
Assert.assertEquals("Homer", author.name);
Assert.assertEquals(asList("The Odyssey", "Iliad"), author.books);
getDs().createAggregation(Book.class)
.group("author", grouping("books", push("title")))
.out("different", Author.class);
Assert.assertEquals(2, getDb().getCollection("different").count());
}
示例3: executeQuery
import com.mongodb.AggregationOptions; //导入依赖的package包/类
@Override
public Object executeQuery(QueryProvider queryProvider) throws MongoQueryException {
Iterator<String> iterator = (Iterator) queryProvider;
int i = 0;
Aggregate aggregate = null;
while (iterator.hasNext()) {
String query = iterator.next();
if (i++ == 0) {
aggregate = jongo.getCollection(queryProvider.getCollectionName()).aggregate(query);
}
else {
Assert.notNull(aggregate, UNEXPECTED_NULL_AGGREGATE_QUERY);
aggregate.and(query);
}
}
Assert.notNull(aggregate, UNEXPECTED_NULL_AGGREGATE_QUERY);
aggregate.options(AggregationOptions.builder()
.allowDiskUse(queryProvider.isAllowDiskUse())
.maxTime(queryProvider.getMaxTimeMS(), TimeUnit.MILLISECONDS)
.build());
ResultsIterator resultsIterator = aggregate.as(HashMap.class);
if (resultsIterator == null || !resultsIterator.hasNext() || Void.TYPE
.equals(queryProvider.getMethodReturnType())) {
return null;
}
final String resultKey = queryProvider.getQueryResultKey();
if (isPageReturnType(queryProvider) && !queryProvider.isAggregate2()) {
throw new IllegalArgumentException("Page can be used as a return type only with @Aggregate2 annotation");
}
if (!queryProvider.isPageable() || (queryProvider.isPageable() &&
List.class.isAssignableFrom(queryProvider.getMethodReturnType()))) {
return getNonPageResults(queryProvider, resultsIterator, resultKey);
}
else if (queryProvider.isPageable() && isPageReturnType(queryProvider)) {
return getPageableResults(queryProvider, resultsIterator);
}
throw new MongoQueryException(QUERY_RETURN_ERROR_STR);
}
示例4: getTagList
import com.mongodb.AggregationOptions; //导入依赖的package包/类
@GET
@Produces("application/json")
@Path("/tags/{product}/{major}.{minor}.{servicePack}/{build}")
public DBObject getTagList(@BeanParam final Coordinates coordinates) {
final DB bdd = this.client.getDB("bdd");
final DBCollection features = bdd.getCollection("features");
List<BasicDBObject> objectList = new ArrayList<BasicDBObject>();
// Build objects for aggregation pipeline
// id option: returns each tag with a list of associated feature ids
objectList.add(new BasicDBObject("$match", coordinates.getReportCoordinatesQueryObject()));
final DBObject fields = new BasicDBObject("tags.name", 1);
fields.put("_id", 0); // comment out for id option
objectList.add(new BasicDBObject("$project", fields));
objectList.add(new BasicDBObject("$unwind", "$tags"));
final DBObject groupFields = new BasicDBObject("_id", "$tags.name");
// groupFields.put("features", new BasicDBObject("$addToSet", "$_id")); //comment in for id option
groupFields.put("amount", new BasicDBObject("$sum", 1));
objectList.add(new BasicDBObject("$group", groupFields));
objectList.add(new BasicDBObject("$sort", new BasicDBObject("amount", -1)));
AggregationOptions options = AggregationOptions.builder().build();
final Cursor output = features.aggregate(objectList, options);
// get _ids from each entry of output.result
final BasicDBList returns = new BasicDBList();
while(output.hasNext()) {
returns.add(output.next().get("_id").toString());
}
return returns;
}
示例5: aggregate
import com.mongodb.AggregationOptions; //导入依赖的package包/类
@Override
public <U> Iterator<U> aggregate(final String collectionName, final Class<U> target, final AggregationOptions options,
final ReadPreference readPreference) {
LOG.debug("stages = " + stages);
Cursor cursor = collection.aggregate(stages, options, readPreference);
return new MorphiaIterator<U, U>(datastore, cursor, mapper, target, collectionName, mapper.createEntityCache());
}
示例6: testDirect
import com.mongodb.AggregationOptions; //导入依赖的package包/类
@Test
public void testDirect() throws Exception {
Command cmd = this.utility.parseCommand("SELECT * FROM Customers");
MongoDBConnection connection = Mockito.mock(MongoDBConnection.class);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
DBCollection dbCollection = Mockito.mock(DBCollection.class);
DB db = Mockito.mock(DB.class);
Mockito.stub(db.getCollection("MyTable")).toReturn(dbCollection);
Mockito.stub(db.collectionExists(Mockito.anyString())).toReturn(true);
Mockito.stub(connection.getDatabase()).toReturn(db);
AggregationOutput output = Mockito.mock(AggregationOutput.class);
Mockito.stub(output.results()).toReturn(new ArrayList<DBObject>());
Mockito.stub(dbCollection.aggregate(Mockito.any(DBObject.class),Mockito.any(DBObject.class))).toReturn(output);
Argument arg = new Argument(Direction.IN, null, String.class, null);
arg.setArgumentValue(new Literal("MyTable;{$match:{\"id\":\"$1\"}};{$project:{\"_m0\":\"$user\"}}", String.class));
Argument arg2 = new Argument(Direction.IN, null, String.class, null);
arg2.setArgumentValue(new Literal("foo", String.class));
ResultSetExecution execution = this.translator.createDirectExecution(Arrays.asList(arg, arg2), cmd, context, this.utility.createRuntimeMetadata(), connection);
execution.execute();
List<DBObject> pipeline = TestMongoDBQueryExecution.buildArray(new BasicDBObject("$match", new BasicDBObject("id", "foo")),
new BasicDBObject("$project", new BasicDBObject("_m0", "$user")));
Mockito.verify(dbCollection).aggregate(Mockito.eq(pipeline), Mockito.any(AggregationOptions.class));
}
示例7: setOptions
import com.mongodb.AggregationOptions; //导入依赖的package包/类
public BuguAggregation setOptions(AggregationOptions options){
this.options = options;
return this;
}
示例8: out
import com.mongodb.AggregationOptions; //导入依赖的package包/类
@Override
public <U> Iterator<U> out(final Class<U> target, final AggregationOptions options) {
return out(datastore.getCollection(target).getName(), target, options);
}
示例9: aggregate
import com.mongodb.AggregationOptions; //导入依赖的package包/类
/**
* Executes the pipeline and aggregates the output in to the type mapped by the target type.
*
* @param target The class to use when iterating over the results
* @param options The options to apply to this aggregation
* @param <U> type of the results
* @return an iterator of the computed results
*/
<U> Iterator<U> aggregate(Class<U> target, AggregationOptions options);
示例10: out
import com.mongodb.AggregationOptions; //导入依赖的package包/类
/**
* Places the output of the aggregation in the collection mapped by the target type.
*
* @param target The class to use when iterating over the results
* @param options The options to apply to this aggregation
* @param <U> type of the results
* @return an iterator of the computed results
* @mongodb.driver.manual reference/operator/aggregation/out $out
*/
<U> Iterator<U> out(Class<U> target, AggregationOptions options);