时间:2021-07-01 10:21:17 帮助过:7人阅读
try.js
var User = require("./user.js"); /** * 插入 */ function insert() { var user = new User({ username : ‘zhangxiao‘, //用户账号 usersex: ‘nan‘, //密码 userage: 17, //年龄 }); user.save(function (err, res) { if (err) { console.log("Error:" + err); } else { console.log("Res:" + res); } }); } insert();
user.js
/** * Created by ZXW on 2017/11/1. */ var mongoose = require(‘mongoose‘); var db = require("./db.js"); var Schema=mongoose.Schema; var UserSchema = new mongoose.Schema({ username:{type:String}, usersex:{type:String}, userage:{type:Number} }); module.exports = mongoose.model(‘User‘,UserSchema);
运行效果:
结果在robmongo工具中查看
数据库:
2017-11-01 23:56:20
mongoose 常用数据库操作 插入
标签:csharp erro 成功 127.0.0.1 ima UI schema insert god