[COMPASS-4881] Export to language doesn't allow new Date() even when exporting to JS/Node.js Created: 11/Jun/21  Updated: 16/Sep/21  Resolved: 16/Jun/21

Status: Closed
Project: Compass
Component/s: Export to Language
Affects Version/s: None
Fix Version/s: No version

Type: Bug Priority: Major - P3
Reporter: Anna Henningsen Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screen Shot 2021-06-11 at 11.01.15 AM.png     PNG File Screen Shot 2021-06-11 at 11.01.31 AM.png     PNG File Screen Shot 2021-06-11 at 11.02.55 AM.png    
Documentation Changes: Not Needed

 Description   

Slack thread: https://mongodb.slack.com/archives/C0U7K0MC3/p1623423645061500

Pipeline:

[{
    $match: {
        timestamp: {
            $gte: new Date(new Date() - 7 * 60 * 60 * 24 * 1000)
        }
    }
}, {
    $group: {
        _id: "$requestedRoute",
        "hits": {
            "$sum": 1
        }
    }
}, {
    $match: {
        hits: {
            $gt: 1
        }
    }
}, {
    $sort: {
        hits: -1
    }
}]

works fine but displays "newDate is not defined" when trying to export to Node.js.



 Comments   
Comment by Massimiliano Marcon [ 16/Jun/21 ]

This type of pipeline is hard to map to different programming languages when exporting it to code.

It's best to take advantage of the aggregation's variable $$NOW and subtract time from there directly in MQL.

Generated at Wed Feb 07 22:37:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.