npmjs.com
npm install mongodb
npm install mongoose
var mongoose = require('mongoose');
var db = mongoose.createConnection('mongodb://192.168.130.128:27017/test');
var monSchema = new mongoose.Schema({
name:{type:String,default:'Peter'},
age:{type:Number},
sex:{type:String}
});
var monModel = db.model('user',monSchema);
var content = {name:"Peter",age:18,sex:'男'};
var monInsert = new monModel(content);
monInsert.save(function(err){
if(err){
console.log(err);
}
else{
console.log('写入数据成功!');
}
db.close();
});