Dates

Querying by dates in MongoDB - the human way

Querying by dates - the human way

If you tried querying by dates in MongoDB, you know how much of a pain it can be. Even if you know the operators, typing the query will raise doubts. Is it ISODate, isoDate or IsoDate? What exactly is the date format? What was the date 2 weeks ago?

How does Mingo handle dates?

Mingo uses human-readable tags for dates in queries. Compare the following two queries:

Regular MongoDB date format:

{
  "createAt": {
    "$gte": ISODate("2020-02-21T00:00:00Z"), // or new Date(…)
    "$lt": ISODate("2020-02-28T00:00:00Z") // or new Date(…)
  }
}

Using Mingo’s date shorthand:

{
  "createdAt": #lastWeek
}

There are two main types of date shorthands available:

Durations

Mingo provides the following duration tags:

#todaysince the start of the today
#yesterdayduring yesterday
#tomorrowduring tomorrow
#thisWeekduring the current week
#thisMonthduring the current month
#thisYearduring the current year
#lastWeekduring the previous week
#lastMonthduring the previous month
#lastYearduring the previous year
#last{number}{period}During the last {number} {period}. Use any number and one of the following periods: minutes, hours, days, weeks, months, years. This is case insesitive, so you may use #last4Years.

Examples: #last2days, #last14weeks, #last3years
#next{number}{period}
During the next {number} {period}. Use any number and one of the following periods: minutes, hours, days, weeks, months, years. This is case insesitive, so you may use #next4Years.

Examples: #next2days, #next14weeks, #next3years
#2021-11-22during any specific date
#2021-11during any specific month
#2021during any specific year
#2021-11-22:2021-11-25between two dates, inclusive
#2021-11:2021-12between two months, inclusive
#2021:2022between two years, inclusive
#since2017-10-03since any specific date
#before2017-10-03before any specific date
#until2017-10-03until any specific date, including the date
#after2017-10-03after any specific date

Moments

To query by a specific moment, use specific dates with the @ prefix, such as @2021-01-29 or @2020-01-29T17:29.

@now or #nowmatches the moment the query was submitted
@2020-01-29T17:29:50+00:00ISO date format - matches specific moment
@17:29:50matches specific hour:minute:second
@17:29matches specific hour:minute

Mingo will understand any valid ISO 8601 format: https://en.wikipedia.org/wiki/ISO_8601

Important

#2021-02-25 and @2021-02-25 are not the same. First refers to a duration (during that day from midnight to midnight) while the second points to the beginning of that day (a specific moment).

Download Mingo now

The best MongoDB GUI Admin. Intuitive • Fast • Secure
Download Now

More features

Aggregation builder
MongoDB Aggregation: simplified and visualized
Read more
7 features that make Mingo so addictive
Let's discover awesome features
Read more
Compare & Sync
Compare and sync entire MongoDB databases
Read more
Indexes
MongoDB Indexes simplified with GUI
Read more
Analyzing data
Analyzing MongoDB data consistency
Read more
Deep links
Deep linking from other apps or websites
Read more