繁体   English   中英

MongoDb $ setIntersection与Java驱动程序

[英]MongoDb $setIntersection with Java Driver

我想使用来自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! 有什么帮助吗?

谢谢...

自己找到的...知道如何就很容易

BasicDBList intersectionList = new BasicDBList();
intersectionList.add( "$structureAttributeValueIdList" );
intersectionList.add( objectIdDBList );
DBObject intersection = new BasicDBObject( "$setIntersection", intersectionList );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM