parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.86k stars 4.78k forks source link

`new Date()` in aggregation node.js #9116

Open mbfakourii opened 5 months ago

mbfakourii commented 5 months ago

New Issue Checklist

Issue Description

Steps to reproduce

I have an Aggregation in mongo shell that works fine.

image But it doesn't output anything in node.js !

var pipeline = [
    {
        $match: {
            _p_enx: "Entrix$" + req.params[KEY_ENTRIX_ID],
        },
    },
    {
        $lookup: {
            from: "KeyLink",
            let: {
                tempPointer: {
                    $substr: ["$_p_klk", 8, -1],
                },
            },
            pipeline: [
                {
                    $match: {
                        $expr: {
                            $and: [
                                {
                                    $eq: ["$$tempPointer", "$_id"],
                                },
                            ],
                        },
                    },
                },
            ],
            as: "klk",
        },
    },
    {
        $match: {
            $or: [
                {
                    "klk.exp": {
                        $gt: new Date(),
                    },
                },
            ],
        },
    },
];

var query = new Parse.Query(EntrixKeyLink);

let responseAggregation = await query.aggregate(pipeline, {useMasterKey: true});

I think there is a problem in new Date().

Actual Outcome

Nothing is output !

Expected Outcome

It should output like the image above

Environment

Server

Database

Client

Logs

n/a

parse-github-assistant[bot] commented 5 months ago

Thanks for opening this issue!

mtrezza commented 5 months ago

Please test with Parse Server 7, the best would be to add a PR with a failed test. We only fix security bugs in Parse Server 6.

mbfakourii commented 5 months ago

Please test with Parse Server 7, the best would be to add a PR with a failed test. We only fix security bugs in Parse Server 6.

I tested in Parse Server 7.0.0 and the problem is not solved !

mtrezza commented 5 months ago

If you remove the date match, then you get the same output on both sides? Did you try { $toDate: new Date() }?

mbfakourii commented 5 months ago

If you remove the date match, then you get the same output on both sides?

Yes

Did you try { $toDate: new Date() }?

I tried this method as below, but it didn't work !

{
    $match: {
        $or: [
            {
                "klk.exp": {
                    $gt: {$toDate: new Date()},
                },
            },
        ],
    },
},
mtrezza commented 5 months ago

Could you write a failing test and submit a PR? The pipeline should be as simple as possible.

mbfakourii commented 5 months ago

Could you write a failing test and submit a PR? The pipeline should be as simple as possible.

What do I expect in this test? what should I compare the pipeline output with?

mtrezza commented 5 months ago

Just could just add the necessary data to the DB to replicate the issue. You expect the query response to be what it should return.