How to find DB creation DB

Hi Team,

How to find DB creation date. Also if we using $external DB for authetication then how to find user creation date.

Hi @BM_Sharma and welcome back to the MongoDB community forum!!

MongoDB does not store the database or the collection creation date. But if you are aware about the oldest document in the collection and if you are using the standard ObjectId() for _id, the value of that field could probably be used to extract the creation data for the collection or database.

The following commands in mongosh

>var db1 = db.sample.find( {}).sort( { _id: 1}).limit(1).next()

Note that this method does not guarantee correctness, since the oldest document could be already deleted. If collection/user creation information is important for your use case, it’s best to record this information separately to ensure accuracy.

Let us know if you have any further questions.

Best Regards