【发布时间】:2019-11-06 06:56:49
【问题描述】:
所以我有一个看起来像这样的关系 mongo 数据库
Location {
_id: ...
shopIDs: <List of Shop IDs in another collection>
}
Shops {
_id: ...
...
}
另外,我已经准备好 GraphQL 设置和 Schema。但是要获得像
这样的查询locations {
shops {
name
}
}
我需要创建另一个将 shopIDs 字段连接到商店集合的解析器,对吗?
所以我做了类似的事情:
Location: {
shopIDs: async ({ shopIDs }, args, context) => {
return await Shop.find({ _id: { $in: shopIDs } });
}
},
但是 shopIDs 是未定义的,当我控制台记录父对象时,它只是父对象的 ID。 现在我的问题是:我真的必须再次使用 mongoose 查找父级才能获取 ShopID 吗? 我还没有找到任何相关的问题,所以我希望这还没有得到回答。 谢谢!
【问题讨论】: