mod-mongo-persistor aggregation, match and unwind example

83 views
Skip to first unread message

Walter Rice

unread,
Apr 9, 2015, 5:59:00 PM4/9/15
to ve...@googlegroups.com
Hi,

I have a working mongo aggregation query like below but I cannot manage to convert it JsonObject type query to use with mod-mongo-persistor. Any help much appreciated..

The working query:


db.getCollection('mycollection-24-03-15').aggregate([
    { "$match": { "marketId": "111223"} },
    { "$unwind": "$runners" },
    { "$match": { "runners.selectionId": 1123 }},
    { "$project": { "status": "$runners.status"}
    }
]);


This will interrogate the document and the inner array "runners", it will return the the "status" of the matching element of the inner array "runners" contained in "mycollection-24-03-15" ignoring all other fields in that inner array element. ... my latest attempt is this...


                /////////////////////////////////////////////////////////////
//                aggregation
                ////////////////////////////////////////////////////////////
                //construct criteria
                //{ "marketId": "111223"}
                JsonObject aggregationMatcherOuterCriteria = new JsonObject();
                aggregationMatcherOuterCriteria.putString("marketId", "1.117880409");
                //{"$unwind", "$runners"}
                JsonObject unwind = new JsonObject();
                unwind.putString("$unwind", "$runners");
//                { "runners.selectionId": 1123 }
                JsonObject aggregationMatcherInnerCriteria = new JsonObject();
                aggregationMatcherInnerCriteria.putNumber("runners.selectionId", 1123);
//                { "status": "$runners.status"}
                JsonObject aggregationProjectionCriteria = new JsonObject();
                aggregationProjectionCriteria.putString("status", "$runners.status");

                           
                            //this is the part i'm stuck on!!!!!!!  
                            json = new JsonObject().putString("collection", "mycollection-24-03-15")
                            .putString("action", "aggregate")
                            .putObject("matcher", aggregationMatcherOuterCriteria)
                            .putString("collection","$runners")
                            .putObject("matcher",aggregationMatcherInner)//;
                            .putObject("keys",aggregationProjectionCriteria);


   JsonObject data = new JsonObject();
                data.putArray("results", new JsonArray());
                // and call the event we want to use
                vertx.eventBus().send("mongodb-persistor", json, new ReplyHandler(req, data));




Walter Rice

unread,
Apr 15, 2015, 9:31:53 AM4/15/15
to ve...@googlegroups.com
Hi all,

Anyone know if this is possible?

Thanks
Reply all
Reply to author
Forward
0 new messages