Reputation: 11
I'm making a GridView in Node.js, But, It's Not connecting to Mongoose and Creating the DB. When I write
show dbs
In my Mongo Shell Then I don't get my Database Created.
This is my Code
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const ejs = require("ejs");
const app = express();
const port = 80;
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
mongoose.connect("mongodb://localhost:27017/griData", {useNewUrlParser: true, useUnifiedTopology: true}, (err)=> {
if(err){
console.log(err);
}
});
console.log(mongoose.connection.readyState);
app.get("/", (req, res)=> {
res.render("main");
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
Upvotes: 1
Views: 27
Reputation: 2168
The database will be created when you will add a first document in the collection automatically.
Upvotes: 1