Skip to content

Month to date query in MongoDB #6069

Closed Answered by palonza
kd-am asked this question in Q&A
May 30, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

hi @kd-am,

The $humanTime format in Redash does not provide a direct option for "start of month" or "current month" as you mentioned.

To achieve the desired functionality, you can use MongoDB's date aggregation operators to calculate the start of the current month dynamically within your MongoDB query.

  1. In Redash, create a new query for your MongoDB data source.
  2. Write your MongoDB aggregation query, including the logic to calculate the start of the current month dynamically.

Here's an example MongoDB aggregation query that calculates the start of the current month and performs further aggregations:

db.collection.aggregate([
  {
    $match: {
      dateField: {
        $gte: {
          $…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kd-am
Comment options

Answer selected by kd-am
# for free to join this conversation on GitHub. Already have an account? # to comment
Category
Q&A
Labels
None yet
2 participants