"Invalid parameter for query: unionWith"

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
    }
  }
];

all the other parameters work fine with the exception of unionWith?

we’ll investigate to see if we can add support for unionWith

1 Like

yea without the union stage it works fine. Thanks, keep me posted please.

is there been any solution yet, or will this take time?

this will take some time until the right person can look at it

1 Like

any updates on this?

1 Like

it looks like it should be a simple change, we have to test it before we add it to production, can you prepare a simple example for test that would work on a new server?

not sure if I understand correctly but it could be tested like this

const test = async => {
  const query = new Moralis.Query("_AddressSyncStatus");
  const pipeline = [
    {
      unionWith: {
        coll: "EthTokenTransfers"
      }
    }
  ];

  const result = await query.aggregate(pipeline);
  
};

ok, that is what I wanted, thanks

1 Like

has it been tested now?

it was not tested yet

can you give an ETA on this?

I would say next week

1 Like

any update on this? been waiting for a reply for some time now. cheers

I didn’t forget about it. It was a busy week. It is not done yet.

1 Like

you can try now to update the server to latest version in order to be able to use unionWith