Could someone please guide me as how to specify the pipeline expression via
spark for both match and project operations in single expression
Hi Sachin,
Similar to MongoDB Aggregation Pipeline in mongo shell, withPipeline
accepts an array of pipeline stage documents via collection Seq. Applying this to your example:
val aggregatedRdd = rdd.withPipeline(Seq(
Document.parse("{ '$match': {'x.t': { '$gte' : 1448908200000}, '$lt': 1448994600000 } }"),
Document.parse("{ '$project': {'_id':0, 'b':'$a.f', 'v':'$a.m', 'q':'$r.q' } }")
))
See also Aggregation Pipeline Behavior for some strategies to optimise aggregation operation.
Regards,
Wan.
String aggregateQuery = "{ $match: { $and: [{gatewaytime : { $gte : " + startTime
+ ", $lte : " + endTime + " }} , {mac : {$in:" + deviceMacs + "} } ]} }";
JavaMongoRDD<Document> rdd = MongoSpark.load(getJSC());
JavaMongoRDD<Document> aggregatedRdd = rdd
.withPipeline(Collections.singletonList(Document.parse(aggregateQuery)));
String aggregateQuery = "{ $match: { $and: [{gatewaytime : { $gte : " + startTime
+ ", $lte : " + endTime + " }} , {mac : {$in:" + deviceMacs + "} } ]} }";
JavaMongoRDD<Document> rdd = MongoSpark.load(getJSC());
JavaMongoRDD<Document> aggregatedRdd = rdd
.withPipeline(Collections.singletonList(Document.parse(aggregateQuery)))
.withPipeline(Collections.singletonList(Document.parse("{$sort: {gatewaytime : -1}")));
The JavaMongoRDD#withPipeline
method takes a Java List
so can be used in the same way as the Scala version:
JavaMongoRDD<Document> aggregatedRdd = rdd
.withPipeline(Arrays.asList(Document.parse(aggregateQuery),
Document.parse("{$sort: {gatewaytime : -1}")));
Note: withPipeline
method will overwrite any existing pipeline, so you must pass the complete pipeline to the method.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/703c0e4d-c10a-45de-8779-df19b99abe1e%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/703c0e4d-c10a-45de-8779-df19b99abe1e%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/948690a0-1928-4a48-b447-7b58c87121b0%40googlegroups.com.