问题描述
是否可以使用单个查询将 AWS DocumentDB 中的 3 个单独集合连接在一起(类似于此处的线程解决方案:How我可以在 MongoDB 聚合管道中执行嵌套的连接"(连接 3 个或更多集合)吗?
Is it possible to join 3 separate collections together in AWS DocumentDB with a single query (similar to the solution to the thread here: How can I perform nested "joins" (joining 3 or more collections) in a MongoDB aggregation pipeline?
我觉得可能不会,但我认为 AWS 不会直接出现并在任何地方明确表示.
I feel like it may not, but I don't think AWS comes right out and specifically says so anywhere.
开发人员指南 说:
Amazon DocumentDB 支持进行相等匹配的能力(对于例如,左外连接)但不支持不相关子查询.
如果我知道什么是不相关的子查询",那会更有帮助.
That would be more helpful if I knew what an "uncorrelated subquery" was.
此外,DocumentDB 支持的 MongoDB API 列表 表示完全不支持 $let
变量运算符.他们所指的 $let
变量运算符是否与以下查询中使用的 $lookup
阶段中的 let
表达式完全相同将 3 个系列合并到一起?
Also, the list of MongoDB APIs that DocumentDB supports says that $let
variable operator is outright not supported. Is the $let
variable operator they're referring to exactly the same as the let
expression within the $lookup
stage that's used in the following query to join together 3 collections?
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 个以上的集合,如果不能,推荐/最有效的方法是什么?
Is joining 3+ collections within a single NoSQL query possible in AWS DocumentDB, and if not, what would be the recommended / most efficient way to do this?
推荐答案
Amazon DocumentDB 支持进行相等匹配(例如,左外连接)的能力,但不支持不相关的子查询.
在 MongoDB 文档中:
相等匹配具有以下语法:
{
$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 不支持第二种语法.
So the 2nd syntax is not supported in DocumentDB.
这篇关于AWS DocumentDB 是否支持在单个查询中加入 3 个以上的集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!