在dart,flutter中,如何从MongoDB集合中获取引用文档的数据以及我们正在获取的实际文档?

e0bqpujr  于 2023-02-05  发布在  Flutter
关注(0)|答案(1)|浏览(118)

我在MongoDB的“products”集合中有一个来自“users”集合的文档引用。当我更新“users”集合中实际文档中的字段时,它已成功更新,但其数据在引用位置未更新。a user in 'users' collection这是“users”集合中的我的用户,它在“products”集合中的文档中被引用,如图所示。user document from 'users' referenced in 'products' collection当我获取这个文档时,我需要用户的数据以及产品的其他数据,但它给我的响应如下所示。query response我尝试过一些包含聚合、管道查询。2我无法得到回应。3可能是我在写查询时哪里错了。4任何帮助都将不胜感激。5谢谢。

t1qtbnec

t1qtbnec1#

我不确定这是您的意思,但是您可以 checkout lookup聚合。

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

}

相关问题