Mongo Db with cli cmd
mongod --version
mkdir c:/dir
mkdir c:/dir/db
mongo
show dbs
use db-name
mongod
localhost:27017
npm i mongoose
const mongoose = require("mongoose");
mongoose
.connect("mongodb://localhost/playground", {
useNewUrlParser: true
})
.then(() => console.log("Connect to mongo db..."))
.catch(err => console.error("could not connect to mongo db ", err));
const course_Schema = new mongoose.Schema({
name: String,
author: String,
tags: [String],
date: {
type: Date,
default: Date.now
},
isPublished: Boolean
});
const Course = mongoose.model("Course", course_Schema); //Course + s is the collection/table name
async function createCourse(_name, _author, _tags, _isPublished) {
const course = new Course({
name: _name,
author: _author,
tags: _tags,
isPublished: _isPublished
});
const result = await course.save();
console.log(result);
}
calling the function
createCourse("node", "Mosh", ["node", "rest"], true);