MongoDb $setIntersection 与 Java Driver
MongoDb $setIntersection with Java Driver
我想使用来自 mongodb 的 java driver 构建以下 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!
有帮助吗?
谢谢...
我自己找到的...当你知道怎么做时很容易
BasicDBList intersectionList = new BasicDBList();
intersectionList.add( "$structureAttributeValueIdList" );
intersectionList.add( objectIdDBList );
DBObject intersection = new BasicDBObject( "$setIntersection", intersectionList );
我想使用来自 mongodb 的 java driver 构建以下 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! 有帮助吗?
谢谢...
我自己找到的...当你知道怎么做时很容易
BasicDBList intersectionList = new BasicDBList();
intersectionList.add( "$structureAttributeValueIdList" );
intersectionList.add( objectIdDBList );
DBObject intersection = new BasicDBObject( "$setIntersection", intersectionList );