I wrote that aggregation using mongo compass and it works on there. When I try to use it with Moralis I get invalid parameter error.
const track_wallets_pipeline = usd_threshold => [
{
unionWith: {
coll: "EthTokenTransfers"
}
},
{
lookup: {
from: "_AddressSyncStatus",
localField: "from_address",
foreignField: "address",
as: "synced_address"
}
},
{
unwind: {
path: "$synced_address"
}
},
{
match: {
$and: [
{
$or: [
{
$expr: {
$eq: ["$from_address", "$synced_address.address"]
}
},
{
$expr: {
$eq: ["$to_address", "$synced_address.address"]
}
}
]
},
{
$expr: {
$gt: ["$usd", 500]
}
},
{
$expr: {
$eq: ["$is_contract_transaction", false]
}
}
]
}
},
{
group: {
objectId: {
from_address: "$from_address",
to_address: "$to_address"
},
tx_count: {
$sum: 1
},
usd: {
$sum: "$usd"
}
}
},
{
project: {
_id: 0,
from_address: "$_id.from_address",
to_address: "$_id.to_address",
tx_count: 1,
usd: 1
}
},
{
sort: {
tx_count: -1,
usd: -1
}
}
];