var mongoose =require (' Mongoose ');
var db = Mongoose.connect ("Mongodb://localhost:27001/test");//local library test database
var Testschem = new Mongoose. Schema ({
Name:{type:string},
age:{type:number,default:0},
Time:{type:date,default:date.now},
Email:{type:string,default: '}
});
var testmodel =db.model (' test1 ', Testschem);//test1 Collection
var testentity=new testmodel ({
Name: ' Eason ',
Age:23,
Email: ' [email protected] '
});
Console.log (Testentity.name);
Save
Testentity.save (function (err) {
if (err) {
Console.log (ERR)
Return
}
Else
{
Console.log (' Save OK ')
}
})
Update
Testmodel.update ({name: ' Eason '},{$set: {name: ' Chen '}},function (err) {
if (err) {
Console.log (' Update not OK ')
Return
}else{
Console.log (' success ')
}
})
Delete
Testmodel.remove ({name: ' Chen '},function (err) {
if (err) {
Console.log (' Remove not OK ')
Return
}else{
Console.log (' Remove success ')
}
})
Inquire
Testmodel.findone ({name: ' Chen '},function (err) {
if (err) {
Console.log (' no result ')
Return
}else{
Console.log (' has one ')
}
})
Mongodb-mongoose additions and deletions to check and change