Open wuye1200 opened 7 years ago
//简单操作 var mongoose = require("mongoose"); //连接 var db = mongoose.connect("mongodb://127.0.0.1:27017/test"); //Schema var TestSchema = new mongoose.Schema({ name : { type:String }, age : { type:Number, default:0 }, email: { type:String }, time : { type:Date, default:Date.now } }); //实例化 var TestModel = db.model("test1", TestSchema ); //new 数据 var TestEntity = new TestModel({ name : "helloworld", age : 28, email: "helloworld@qq.com" }); //保存 TestEntity.save(function(error,doc){ if(error){ console.log("error :" + error); }else{ console.log(doc); } });