I am new to mongodb and need an equivalent code in java for the below
db.asset.aggregate([{
$unwind : '$asset'
}, {
$match : {
'asset.status' : {
$in : ['1', '2', '3']
},
'asset.siteid' : {
$in : ['123']
}
}
}
]).pretty()
I tried the following but it didn't help-out
DBObject unwind = new BasicDBObject("$unwind", "$dp.asset");
DBObject match = BasicDBObjectBuilder.start().push("$match")
.push("dp.asset.status").add("$in", ['ACTIVE', 'LIMITEDUSE', 'OPERATING'])
.push("dp.asset.siteid").add("$in", ['BEDFORD']).get();
AggregationOutput aggr = collection.aggregate(Arrays.asList(unwind, match));
Note : i am using mongodb 3.4.1
Not sure why you are using single quotes while passing the array value.
The right syntax to pass the values are
Or
For 3.x drivers, you should be using Document.
Code for Mongo Query.
The fields in your mongo shell aggregation operation do not match with the ones in the current Java pipeline.
Apart from that anomaly, you could try the following pipeline: