there is no new data in the database after executing save (). Is it because the new version of MongoDB needs to create users and log in securely by authentication?
the complete code is as follows:
movie.js file
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const MovieSchema = new Schema(
{
title:{type:String, required:true},
post:{type:String},
director:{type:String},
date:{type:String},
score:{type:String},
},
{timestamps: true}
);
module.exports = mongoose.model("Movie", MovieSchema);
index.js file
// express express app
const express = require("express");
const app = express();
//mongoose
const mongoose = require("mongoose");
//
mongoose.connect("mongodb://localhost:27017/movie-db",{useNewUrlParser:true});
const db = mongoose.connection;
//MovieSchema
const Movie = require("../module/movie")
//
db.on("error", console.log);
//success
db.once("open", ()=>{
let movie = new Movie({title: ""});
movie.save(function(err){
if(err) console.log(err)
})
console.log("success2!");
});
app.get("/",function(req, res){
res.send("Hello world!");
})
app.listen(3000, function(){
console.log("3000");
});
run node index.js
and print the following