Skip to content

๐Ÿ—ƒ๏ธ MongoDB Query Examplesยถ

This page provides practical MongoDB query examples for common troubleshooting and data inspection tasks.


๐Ÿ”Ž Find Users Created After a Specific Dateยถ

To search for users created after a certain date, use the following query:

db.users.find({
  createdAt: { $gt: ISODate("2025-09-03T20:00:00Z") }
})
{
createdAt: { $gt: ISODate("2025-09-22T00:00:00Z"),$lt: ISODate("2025-09-23T00:00:00Z") }
}

Date Format

Use ISODate for accurate date comparisons in MongoDB queries.


๐Ÿงฎ Aggregation: Match Documents by Creation Dateยถ

To filter documents in an aggregation pipeline where createdAt is after a specific date:

{
  $match: {
    createdAt: {
      $gt: new Date("2025-09-02T20:20:00Z")
    }
  }
}

Aggregation Context

Place this $match stage at the appropriate point in your aggregation pipeline.


๐Ÿ“š Additional Resourcesยถ