MongoDB Aggregration Framework and Java Driver making $or condtion work
I am working on a method that queries a mongoDB using the aggregator
framework. I have built up the aggregate but I keep getting the following
exception:
Pipeline::run(): unrecognized pipeline op \"$or"
If I understand correctly when you append or add DBObjects to the query
they are implicitly added as and operations. I may be really tired right
now but I can't think of a way to or two conditions with the aggregation
framework.
The following is a snippet of my code:
DBObject matchCriteriaTransmitter = new BasicDBObject("$match",
new BasicDBObject("someKey": "someValue").
append("someKey": "someValue"));
DBObject matchCriteriaReceiver = new BasicDBObject("$match",
new BasicDBObject("someKey": "someValue").
append("someKey": "someValue"));
BasicDBList or = new BasicDBList();
or.add(matchCriteriaTransmitter);
or.add(matchCriteriaReceiver);
DBObject matchCriteria = new BasicDBObject("$or", or);
DBObject sortCriteria = new BasicDBObject("$sort",
new BasicDBObject("compoundIndex.scenarioDtg", -1));
DBObject limitCriteria = new BasicDBObject("$limit", 1);
DBCollection collection = dao.getCollection();
AggregationOutput output = collection.aggregate(matchCriteria,
sortCriteria, limitCriteria);
Any insight is greatly appreciated!
No comments:
Post a Comment