question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Date format in parameters doesn't work (MongoDB Query)

See original GitHub issue

Issue Summary

When using date parameters in MongoDB query, we can’t use the date format, but only the number one (timestamp)

Steps to Reproduce

{
  "$match": {
     "_created_at": {
       "$gte": {
         "$date": "{{fromDate}}"
       },
       "$lt": {
         "$date": "{{toDate}}"
        }
       }
    }
}

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
SebC99commented, Nov 2, 2018

What works for me is using $ISODate:

"_created_at": {
   "$gte": "ISODate(\"{{ start }}\")"
}
0reactions
GaetanLhoestcommented, Jul 31, 2019

Hi, is there any update on this?

I would like as well to count events during the last hour, and made the following query:

{
    "collection": "live-providers",
    "aggregate": [{
        "$match": {
            "date": { 
                "$gt": "new ISODate(ISODate().getTime() - 1000 * 60 * 60)"
            }
        }
    } ,{
        "$group": {
            "_id": "$provider",
            "count1": {
                "$sum": "$insert"
            },
            "count2": {
                "$sum": "$delete"
            },
            "coun3t": {
                "$sum": "$updates"
            }
        }
    }, {
        "$sort": [{
            "name": "count1",
            "direction": 1
        }, {
            "name": "count2",
            "direction": -1
        }, {
            "name": "count3",
            "direction": -1
        }, {
            "name": "_id",
            "direction": -1
        }]
    }]
}

but it does not return anything, if I remove the $match section, it count on all the documents, and not only the last hour.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with datetime as string - MongoDB
Let's say some external component inserts data into my database, with a field called “startDate”. They store this value as an ISO 8601 ......
Read more >
Date format in Mongo DB is wrong - Stack Overflow
In Database the date format stored is as below. Adding two same fields but values are different. ... Due to the the above...
Read more >
Working with dates and times in MongoDB - Prisma
You can pass call $dateToString() with a Date object, a format string specifier, and a timezone indicator. MongoDB will use the format string...
Read more >
How to Format the Date in MongoDB - Database.Guide
Example. Suppose we have a collection called cats with the following documents: · Date in dd/mm/yyyy Format. Here's another example that converts ...
Read more >
Custom Date Formats - Tableau Help
To format a date field in the view, right-click (Control-click on a Mac) the field and choose Format. This will open the Format...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found