如何使用变量到$查找mongo系列

发布于 2025-02-02 13:25:04 字数 462 浏览 1 评论 0原文

我有3个集合:用户,钱包和货币。

我需要进行查询,以获取每个用给定货币钱包的用户。

用户不与货币共享属性,但钱包都与两者共享属性。

用户拥有和_id和钱包具有相应的_userid。钱包的货币属性是一个字符串,与属性货币的名称相对应。

是否可以使用先前定义的货币名称变量来检查平等并从拥有此货币的用户那里获取每个钱包?

现在,我使用匹配的聚合,我想将其添加到顶部。

db.user.aggregate([
  {
    $match: {some matches}
  },
  { 
    $lookup: //I assume I need to use a $lookup but i cant figure out if its possible to use a         variable here.
  },
  {
    $project
  }, etc
]);

I have 3 collections: users, wallets and currencies.

I need to make a query that gets every user that has a wallet of a given currency.

Users dont share properties with currencies, but wallets share properties with both.

Users have and _id and wallets have a corresponding _userId. And wallets have a currency property that is a string and corresponds to the name property currencies have.

Is it possible to use a previously defined currencyName variable to check for equality and get every wallet from a user that has this currency?

Right now im using an aggregation with a match, and i would like to add this on top.

db.user.aggregate([
  {
    $match: {some matches}
  },
  { 
    $lookup: //I assume I need to use a $lookup but i cant figure out if its possible to use a         variable here.
  },
  {
    $project
  }, etc
]);

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

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

发布评论

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