我有2个系列:交易&帐户。
我需要将帐户加入交易,以便我可以在Accounts.acctType字段上进行分组。问题是Transactions.accountId的类型是'string',Accounts._id的类型是'Int32'。
有什么办法可以避免这个问题,而无需更改Transactions.accountId类型?
当前查找代码:
$lookup: {
from: 'accounts',
localField: accountId,
foreignField: '_id',
as: 'accountData'
}
我需要什么:
$lookup: {
from: 'accounts',
localField: Number(accountId), //something like this
foreignField: '_id',
as: 'accountData'
}
或者:
$lookup: {
from: 'accounts',
localField: accountId,
foreignField: '_id.toString()', //or something like this
as: 'accountData'
}
如果没有看到您的数据的例子,并且了解这些不同领域应该如何匹配,很难回答。 –