How to find the last update time of a collection and database

My website used a lot of data from Mongodb, sometimes if my database/collection didn’t update for a while, it means that my system is probably broken, therefore I want to get the last update (document) time of a database and collection, how can I get it accurately?


Welcome to the MongoDB Community!

May I ask what specifically you mean by “system is probably broken”? Could you please clarify this more in order to assist you better?

Additionally, also share the MongoDB version you are using and where it is deployed, is it MongoDB Atlas or on-prem?


If you just want to check whether there is any updating operation occasionally, db.currentOp() can help you find the active connections to MongoDB and what they are doing. Since the output of db.currentOp() is long and lengthy, you can define your own function to capture only the content you are interested in:

  function(c) {
    print(" client: ", c.client);
    print(" appName: ", c.appName);
    print(" active: ",;
    print(" currentOpTime: ", c.currentOpTime);
    print(" op: ", c.op);
    print(" ns: ", c.ns);
    print(" command: ", c.command);
    print("= = = = = = = = = = = \n");