Node through the mongoose to realize the deletion and modification of MongoDB
New File Test.jsThe contents are as follows:
var mongoose = require (' Mongoose '), Schema = Mongoose. Schema;mongoose.connect (' mongodb://localhost/test '); var blogschema = new Schema ({ id : {type:number, index: True} , title : {type:string}}), Mongoose.model ("blog", Blogschema), var blog = mongoose.model ("blog"); Get model instance var blog1 = new Blog (), blog1.id = 4;blog1.title= "ully"; Blog1.save (function (err) { //store if (err) { Console.log (' Save Failed '); } Console.log (' save Success ');}); Blog.find ({id:4},function (Err,docs) {///Query ID 4 record console.log (docs); Console.log (' find success ');}); Blog.update ({id:4,title: "Upill"},function (err,docs) {//Update Console.log (docs); Console.log (' update Success ');}); Blog.remove ({id:4},function (Err,docs) {//delete records with ID 4 console.log (docs); Console.log (' remove success ');});
Note: When performing a database view in Monogo, to query blogs (here blogs is because the model of the blog, I think this is the mongoose automatically generated table structure) table, that is
Use test; Db.blogs.find ();
Node through the mongoose to realize the deletion and modification of MongoDB