Wanted to check number of insert happening to a collection in daily basis

Hey @Prince_Das,

There are a number of ways you can use to check DML happening in a collection. You can try using mongostat which provides a quick overview of running instances and mongotop which provides statistics on a per-collection level.

You can also try using change streams in MongoDB which allows applications to access real-time data changes. With change streams, you can track data changes in a single collection, a database, or even an entire deployment. For the insert operation, the change event will give an output like this:

{
   "_id": { <Resume Token> },
   "operationType": "insert",
   ...
   "ns": {
      "db": "example",
      "coll": "testing"
   },
   "fullDocument": {
      "_id": ObjectId("599af247bb69cd81261c345f"),
      ...
   }
}

Here, the ns field shows the namespace (database and or collection) affected by the event.

Regards,
Satyam

5 Likes