如何使用变量到$查找mongo系列
我有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论