使用GraphQL(Nestjs)生成关注用户项目的提要

发布于 2025-02-14 01:17:28 字数 529 浏览 1 评论 0原文

我是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 the author are stored as ids but can be populated with the full object

thanks!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东北女汉子 2025-02-21 01:17:28

我通过使用以下杂种查找来解决它:

this.productModel
      .find({
        seller: { $in: following },
      })

其中是用户所关注的的数组,然后我用seller .populate('卖方('seller) ').exec()

I solved it by using the following mongoose find:

this.productModel
      .find({
        seller: { $in: following },
      })

where following is the array of id's the user is following, then I populate the seller with .populate('seller').exec()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文