Skip to content

Instantly share code, notes, and snippets.

@saravanapriyanm
Last active August 1, 2023 13:29
Show Gist options
  • Save saravanapriyanm/b6b70773aac9de16e49aa5986d0205b0 to your computer and use it in GitHub Desktop.
Save saravanapriyanm/b6b70773aac9de16e49aa5986d0205b0 to your computer and use it in GitHub Desktop.
MongoDB

$match: { $expr: {$eq: [{$week: "$Document.data.DATE"}, 27]} }

$match: { "Document.data.DATE": { $gte: ISODate('2023/07/04'), $lt: ISODate('2023/07/05'), } }

[
  {
    $match: {
      FormId: "f80e8870-ba52-4638-857d-039f4ee6a9c8",
      IsLatestApproved: true,
    },
  },
  {
    $project: {
        fieldType: {
          $type: "$Document.data.DATE",
        },
      },
  },
  {
    $group: {
        _id: "$fieldType",
        v: { $sum: 1 },
      },
  },
]

[ { $match: { FormId: "f80e8870-ba52-4638-857d-039f4ee6a9c8", IsLatestApproved: true, }, }, { $sort: { "Document.data.DATE": -1 }, }, { $group: { _id: { year: {$year:"$Document.data.DATE"}, month: {$month:"$Document.data.DATE"}, day: {$dayOfMonth:"$Document.data.DATE"} } } }, { $skip:2 }, { $limit: 1 } ]

[ { $match: { FormId: "f80e8870-ba52-4638-857d-039f4ee6a9c8", IsLatestApproved: true, }, }, { $sort: { "Document.data.DATE": -1 }, }, { $group: { _id: { year: {$year:"$Document.data.DATE"}, month: {$month:"$Document.data.DATE"}, day: {$dayOfMonth:"$Document.data.DATE"} } } }, { $skip:2 }, { $limit: 1 } ]

[ { $match: { FormId: "f80e8870-ba52-4638-857d-039f4ee6a9c8", IsLatestApproved: true, }, }, { $sort: { "Document.data.DATE": -1 }, }, { $limit: 1 } ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment