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.