I am running into a weird issue with one of my functions. In the example below, when I only query either “query_1” or “query_2” its working normally. When I query both queries I get the error from the subject of this thread.
Doesnt make any sense to me. Why would the aggregation work on a single call but not on both?
Moralis.Cloud.define("trackWallets", async request => {
try {
const usd_threshold = request.params.usd_threshold || 10000;
const pipeline = track_wallets_pipeline(usd_threshold);
const query_1 = new Moralis.Query("EthTransactions");
const query_2 = new Moralis.Query("EthTokenTransfers");
const result_1 = await query_1.aggregate(pipeline);
const result_2 = await query_2.aggregate(pipeline);
return {
ethTransactions: result_1.length,
tokenTransfers: result_2.length,
result1: result_1,
result2: result_2
};
} catch (error) {
logger.info("Error: " + error);
return error;
}
});
const track_wallets_pipeline = usd_threshold => [
{
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
}
}
];