Mongoose creating Database without any Record/document

I read in official documentation on MongoDB that

MongoDB only creates the database when you first store data in that database.

I created database using mongosh and found it to be true. Now I am trying to create database using mongoose module in Nodejs. I am just creating database and not adding any records.
This is my code

const mongoose = require('mongoose');

require('dotenv').config();

const itemadd = require("./model/schema.js")   // Js file having schema 

async function start()
{
    try {
        
      await  mongoose.connect(process.env.mongo_uri)   // line ABC 
        console.log("We are successful")
    } catch (error) {
        console.log("We encountered an error :-\n",error)
    }

}

start();

Now in this piece of code I am just connecting to my server at atlas in line ABC. However upon checking the atlas I am seeing that the database has been created with collection inside it (collection name as per given in schema). Although there is no document/record in it , but still database has been created.
Can anyone tell me how without any record, database was created.

ODM does ODM things.

Could also depend on your model, if there is an indexed field (other than _id) then creating the index will create the namespace (database and collection).

// no test db 
s0 [direct: primary] test> show dbs
admin   172.00 KiB
config  164.00 KiB
local   556.00 KiB

// Create an index in test.foo
s0 [direct: primary] test> db.test.foo.createIndex({a:1})
a_1

// Hello database test
s0 [direct: primary] test> show dbs
admin   172.00 KiB
config  164.00 KiB
local   556.00 KiB
test     12.00 KiB
1 Like