微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AWS DocumentDB 是否支持在单个查询中加入 3 个以上的集合?

如何解决AWS DocumentDB 是否支持在单个查询中加入 3 个以上的集合?

是否可以通过单个查询将 AWS DocumentDB 中的 3 个单独集合连接在一起(类似于此处的线程解决方案:How can I perform nested “joins” (joining 3 or more collections) in a MongoDB aggregation pipeline?

我觉得可能不会,但我认为 AWS 不会直接出现并在任何地方明确表示。

Developer Guide 说:

Amazon DocumentDB 支持进行相等匹配的能力(对于 例如,左外连接)但不支持不相关 子查询

如果我知道什么是“不相关的子查询”,那会更有帮助。

此外,list of MongoDB APIs that DocumentDB supports 表示完全不支持 $let 变量运算符。他们所指的 $let 变量运算符是否与 let 阶段中的 $lookup 表达式完全相同,该表达式在以下查询中用于将 3 个集合连接在一起?

db.customers.aggregate([
  {
    $lookup: {
      from: "orders",let: { customer_id: "$customer_id" },pipeline: [
        { $match: { $expr: { $eq: ["$$customer_id","$customer_id"] } } },{
          $lookup: {
            from: "orderitems",localField: "order_id",foreignField: "order_id",as: "items"
          }
        }
      ],as: "orders"
    }
  }
])

在 AWS DocumentDB 中是否可以在单个 Nosql 查询中加入 3 个以上的集合,如果不能,推荐/最有效的方法是什么?

解决方法

DocumentDB doc中:

Amazon DocumentDB 支持进行相等匹配(例如,左外连接)的能力,但不支持不相关的子查询。

MongoDB doc中:

相等匹配具有以下语法:

{
   $lookup:
     {
       from: <collection to join>,localField: <field from the input documents>,foreignField: <field from the documents of the "from" collection>,as: <output array field>
     }
}

不相关的子查询具有以下语法:

{
   $lookup:
     {
       from: <collection to join>,let: { <var_1>: <expression>,…,<var_n>: <expression> },pipeline: [ <pipeline to execute on the collection to join> ],as: <output array field>
     }
}

所以 DocumentDB 不支持第二种语法。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。