使用GraphQL(Nestjs)生成关注用户项目的提要
我是GraphQL的新手,我有一些可以互相关注的用户,他们有产品列表,创建您关注的用户的产品的供稿是什么?
用户
具有与products
有关的属性listing
(该属性与用户有关,其属性称为作者
)
基本上,用户看起来像这样:
User object
{
...
listing: [ "id1", "id2" ]
}
类似的产品:
Product object
{
...
author: { User1 }
}
编写查询以从关注的用户那里获取产品的最佳方法是什么?
其他也许有用的信息:
- 数据存储在mongoDB数据库中
listings
和作者
存储为ID,但可以用完整的对象填充,
谢谢!
I'm new to graphql, I have some users that can follow each other and they have a list of products, what would be the way to go to create a feed of products of the users you follow?
The user
has a property called listing
that has a relation to the products
(which has a relation to the user with a property called author
)
Basically the user looks like this:
User object
{
...
listing: [ "id1", "id2" ]
}
and the product like this:
Product object
{
...
author: { User1 }
}
what would be the best approach to write a query to get the products from the followed users?
other maybe useful information:
- the data is stored in a mongodb database
- the
listings
and theauthor
are stored as ids but can be populated with the full object
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用以下杂种查找来解决它:
其中是用户所关注的的数组,然后我用
seller
.populate('卖方('seller) ').exec()
I solved it by using the following mongoose find:
where
following
is the array of id's the user is following, then I populate theseller
with.populate('seller').exec()