如何从一个集合中复制文档的主要键,并将其保存在类似数据库中的另一个集合中

发布于 2025-02-11 07:04:20 字数 290 浏览 0 评论 0原文

我想使用$查找加入数据库中的两个集合。我需要从一个集合中获取主键(“ _ ID”),并将它们添加到另一个集合中,为“ ID2”,以便使用查找。如何执行此操作?

我想复制的主要钥匙的第一个集合 “第一个集合,其主要键我要复制”

第二个集合,我希望第一个集合的主要键复制为“ _id2”

“收集到第二个集合,并将其保存为“ _id2”。他们执行$查找,并将两个收藏夹与我的外国菲尔德(我的外国人)在一起。

I want to use $lookup to join two collections in my database. I need to take primary keys("_id") from one collection and add them to another collection as “id2” in order to use lookup. How can I perform this operation?

First Collection whose primary key I want to copy
First Collection whose primary key I want to copy

Second collection where I want the First collection's primary key copied as "_id2"
Second collection where I want the First collection's primary key copied as "_id2"

I want to copy the “_id” for first collection to the second collection and save it as “_id2”. And them perform $lookup and get both the collections together with my foreignField being “_id2”.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文