day 8-mongodb接続
1399 ワード
メモ
var mongoose=require("mongoose");
mongoose.connect('mongodb://localhost/my_database');
var Comment=new Schema({
name:{type:String,default:"hahaha"},//default
age:{type:Number},
sex:{type:String},
buff:Buffer
});
var monModel=db.model("user",Comment);
var content={name:" ",age:18,sex:" "};
var monInsert=new monModel(content);
monInsert.save(function(err){
if(err){
console.log(err);
}else{
console.log(" ");
}
db.close();
});
var content={};//
var field={name:" "};//
monModel.find(content,fied,function(err,result){
if(err){
console.log(err);
}else{
console.log(" ");
}
db.close();
})
var tiaojian={name:" "};
var gengxi={$set:{name:" "}};
monModel.find(tiaojian,gengxi,funtion(err){
if(err){
console.log(err);
}else{
console.log(" ");
}
db.close();
})
var tiaojian={name:" "};
monModel.remove(tiaojian,function(err){
if(err){
console.log(err);
}else{
console.log(" ");
}
db.close();
})