Jongo Mongo - Unwind with match example

September 7, 2016

Example of an unwind query in Jongo

MongoDB query

<![CDATA[ db.getCollection(‘<collection_name>’) .aggregate([{$unwind : “$offers.offers”},{$match:{“offers.offers.seller.sellerId”:“999”}}]) ]]>
SyntaxHighlighter.highlight();

Jongo query

<![CDATA[ db.getCollection(‘<collection_name’) .aggregate([{$unwind : “$offers.offers”},{$match:{“offers.offers.seller.sellerId”:“999”}}]) Aggregate.ResultsIterator<class_name> products = <class_name>.<method_name>() .aggregate("{$unwind: ‘$offers.offers’}") .and("{$match:{offers.offers.seller.sellerId: #}}", String.valueOf(retailer.getId())) .as(<class_name> .class); ]]>
SyntaxHighlighter.highlight();