在Java异步驱动程序中使用查找管道

问题描述 投票:0回答:1

试图使用异步Java驱动程序进行查找以加入2个集合。但是我找不到要使用的正确语法,因为我找不到任何有关使用$ lookup命令的Let(变量)版本正常运行的语法的文档。

这里是使用什么(它找不到任何匹配项:]:>

final List<Bson> lookUppipeline = new ArrayList<>();
final List<Variable<?>> variables = Arrays.asList(new Variable<>("id", "$_id"));
lookUppipeline.add(match(eq("object_id", "$$id")));
final Bson lookup = lookup("values_collection", variables, lookUppipeline, "tag_values");
final AggregateIterable<ApiJsonObject> findIter = info_collection.aggregate(Arrays.asList(lookup, skip(0), limit(1_000), project(exclude(EXCLUDES_LIST))));

$_id中的info_collection基本上等于object_idvalues_collection

我需要以其他方式创建变量还是匹配项相等?如果我使用查找方法的外键版本,则可以使用,但是我需要使用管道,因为我还要添加其他内容。

有些示例使用同步驱动程序,但不使用异步驱动程序。

mongodb查询的语法是

db.info_collection.aggregate([
   {
      $lookup:{
          from: "values_collection",
          let: { id: "$_id" },
          pipeline: [
             { $match:
                { $expr:
                   { $and:
                      [
                        { $eq: [ "$object_id",  "$$id" ] }
                      ]
                   }
                }
             }
          ],
          as: "tag_values"
        }
   }
])

以下是一些示例数据(已精简但所有相关):

info_collection

[
    {"_id":"cce9ec95-dd03-4066-89c5-86227be70503", "Name":"Object1" }
    {"_id":"cce9ec95-dd03-4066-89c5-86227be70503", "Name":"Object2" }
    {"_id":"cce9ec95-dd03-4066-89c5-86227be70503", "Name":"Object3" }
    {"_id":"cce9ec95-dd03-4066-89c5-86227be70503", "Name":"Object4" }
    {"_id":"cce9ec95-dd03-4066-89c5-86227be70503", "Name":"Object5" }
]

values_collection

[
    {"object":"cce9ec95-dd03-4066-89c5-86227be70503", "_id":{"$oid":"5e1cee26610b668017537cc2"}, "Value":"test1", "Tag":1},
    {"object":"6494bcec-c94f-4421-9f5a-84a76edda8fd", "_id":{"$oid":"5e1cee26610b668017537cc4"}, "Value":"test2", "Tag":1},
    {"object":"ea40aaf7-1d7c-4bf2-8a98-93cfbf62035d", "_id":{"$oid":"5e1cee26610b668017537cc6"}, "Value":"test3", "Tag":1},
    {"object":"7556a86d-4962-4220-8a77-10655e8e4376", "_id":{"$oid":"5e1cee26610b668017537cc8"}, "Value":"test4", "Tag":1},
    {"object":"f78d4302-0756-47bb-aaff-c93744d147fe", "_id":{"$oid":"5e1cee26610b668017537cca"}, "Value":"test5", "Tag":1},
    {"object":"06ade084-3e2a-42eb-9063-5059c447e518", "_id":{"$oid":"5e1cee26610b668017537ccc"}, "Value":"test6", "Tag":1}
]

试图使用异步Java驱动程序进行查找以加入2个集合。但是我找不到正确的语法,因为我找不到关于使用Let(...

java mongodb mongo-java mongo-java-driver
1个回答
0
投票

找出答案,我想使用汇总不能使用速记助手功能,而必须将参数作为文档传递。

© www.soinside.com 2019 - 2024. All rights reserved.