我想建立以下MongoDB的JSON的查询与MongoDB中的Java驱动程序:
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,部分!有什么帮助吗?
谢谢...
我自己找到它......很容易,当你知道如何
BasicDBList intersectionList = new BasicDBList();
intersectionList.add( "$structureAttributeValueIdList" );
intersectionList.add( objectIdDBList );
DBObject intersection = new BasicDBObject( "$setIntersection", intersectionList );
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句