我想用来自mongodb的java驱动程序构建以下mongodb-json-query:
db.item.aggregate([
{'$project': { attr: {
$setIntersection:["$structureAttributeValueIdList", [ObjectId("54bfba08ef6643acaa5be2c9")]]
}, _id : 0, document: "$$ROOT"
}},
{ "$unwind": "$attr" },
{ "$match": { "document.stateDeleted" : 0 } }]);
到目前为止我所拥有的是:
DBObject intersection =
new BasicDBObject( "$setIntersection", ???? );
DBObject fields = new BasicDBObject( "attributes", intersection );
fields.put( " document", "$$ROOT" );
fields.put( "_id", 0 );
DBObject project = new BasicDBObject( "$project", fields );
DBObject unwind = new BasicDBObject( "$unwind", "attributes" );
DBObject match =
new BasicDBObject( "$match", new BasicDBObject( "document.stateDeleted", 0 ) );
List< DBObject > pipeline = Arrays.asList( project, unwind, match );
AggregationOutput output = operations.getCollection( "item" ).aggregate( pipeline );
但我不知道如何构建setIntersection-Part! 有什么帮助吗?
...谢谢
答案 0 :(得分:0)
自己找到它......当你知道如何
时非常容易BasicDBList intersectionList = new BasicDBList();
intersectionList.add( "$structureAttributeValueIdList" );
intersectionList.add( objectIdDBList );
DBObject intersection = new BasicDBObject( "$setIntersection", intersectionList );