[ https://issues.apache.org/jira/browse/BEAM-6241?focusedWorklogId=182820&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-182820 ]
ASF GitHub Bot logged work on BEAM-6241: ---------------------------------------- Author: ASF GitHub Bot Created on: 09/Jan/19 03:08 Start Date: 09/Jan/19 03:08 Worklog Time Spent: 10m Work Description: sandboxws commented on pull request #7293: [BEAM-6241] Added limit and aggregates support to MongoDbIO URL: https://github.com/apache/beam/pull/7293#discussion_r246247611 ########## File path: sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/QueryBuilder.java ########## @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.io.mongodb; + +import com.mongodb.BasicDBObject; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; +import com.mongodb.client.model.Aggregates; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Projections; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import org.bson.BsonDocument; +import org.bson.Document; +import org.bson.codecs.BsonValueCodecProvider; +import org.bson.codecs.IterableCodecProvider; +import org.bson.codecs.ValueCodecProvider; +import org.bson.codecs.configuration.CodecRegistries; +import org.bson.conversions.Bson; +import org.bson.types.ObjectId; + +/** + * Builds an AggregateIterable pipeline using multiple options. + * + * @author Ahmed Elhossaini Review comment: Will do. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 182820) Time Spent: 20m (was: 10m) > MongoDbIO - Add Limit and Aggregates Support > -------------------------------------------- > > Key: BEAM-6241 > URL: https://issues.apache.org/jira/browse/BEAM-6241 > Project: Beam > Issue Type: Improvement > Components: io-java-mongodb > Affects Versions: 2.9.0 > Reporter: Ahmed El.Hussaini > Assignee: Ahmed El.Hussaini > Priority: Major > Labels: easyfix > Fix For: 2.10.0 > > Time Spent: 20m > Remaining Estimate: 0h > > h2. Adds Support to Limit Results > > {code:java} > MongoDbIO.read() > .withUri("mongodb://localhost:" + port) > .withDatabase(DATABASE) > .withCollection(COLLECTION) > .withFilter("{\"scientist\":\"Einstein\"}") > .withLimit(5));{code} > h2. Adds Support to Use Aggregates > > {code:java} > List<BsonDocument> aggregates = new ArrayList<BsonDocument>(); > aggregates.add( > new BsonDocument( > "$match", > new BsonDocument("country", new BsonDocument("$eq", new > BsonString("England"))))); > PCollection<Document> output = > pipeline.apply( > MongoDbIO.read() > .withUri("mongodb://localhost:" + port) > .withDatabase(DATABASE) > .withCollection(COLLECTION) > .withAggregate(aggregates)); > {code} > -- This message was sent by Atlassian JIRA (v7.6.3#76005)