[SOLVED] How to use group by and date filter

Hi everyone!

Thanks for your moralis service.

I am going to use group by filter by date.
For example, I am going to get the total prices by collectionAddress after a certain date.
So I used this code, but it returns an empty array.

let pipeline = [
                match: {
                    updatedAt: {
                        $gte: new Date(parseInt(request.params.from))
                group: {
                    objectId: '$collectionAddress',
                    total: {
                        $sum: '$price'

How can I fix this issue?


you may have to use _updated_at instead of updatedAt, you will find the solution in other similar threads

Hi @cryptokid!

Thanks for your reply.

I used _updated_at instead of updatedAt, but it is still not working.

I tried to find other solutions in the other threads, but not found the solution.

try different values here, make sure that the date is the expected format

did you also try updated_at?

I tried to use the default date(new Date(0)) and it also failed.
And I tried to use updated_at instead of updatedAt, but it also failed.
:weary: :weary: :weary:

can you try only with the match pipeline? to make sure that the issue is there

Ah~~, it is not working.
But if I use this code, date filter is working.

query.greaterThan('updatedAt', new Date(xxx));

But in this case, if I add group on the pipeline, it is not working.

this worked at that time, but it wasn’t a match, if you change it to $lte then it works?

When I use $lt instead of $gt, it returns the items after the certain time.
Should I neet to use $lt for this specification?

it may be a different issue, maybe it expects a different date format, try with iso format

try with different combinations for $lt, $gt

So you mean that I need to compare the date time in iso string format?

Try different date formats, you will find examples in other forum threads

Yeah, I found the solution on the other thread and it works so well.
Thanks a lotttttttttttt

1 Like