Query WatchedEthAddress with aggregation throws master key required

const query = new Moralis.Query("WatchedEthAddress");
        const pipe = [
            {
                $match: {
                    $expr: { $gte: [{ $toInt: "$balance" }, ethbalance] }
                }
            }
        ]

        const result = await query.aggregate(pipe)

throws unauthorized - master key required error.

When I query the collection with a normal .find() for example I get results. Using aggregate its not working. How to solve this?

I think that you already solved that master key requirement by adding master key in Moralis.start as parameter, in case that you are running that from nodejs

adding here the solution that it looks like you found for that query:

   const pipe = [
                {
                    match: {
                        $expr: { $gte: [{ $toDouble: "$balance" }, ethbalance]}

                    }
                }
            ]

Thank you, already solved this same way as you provided an answer. Cheers

1 Like