Express 4.x 框架上 model和schema结合的文件怎么追加字段
发布于 2 个月前 作者 JcBy 177 次浏览 来自 问答

我是在慕课网上自学的,不过属于只看了一半的那种;

他将model和schema结合在了一起,比如

var mongoose = require(‘mongoose’); var UserSchema = new mongoose.Schema({ nickname: String, headimgurl: String, acounts: String, password: String, sex: Number, country: String, city: String, write: { create: String, update: String } }); mongoose.model(‘User’, UserSchema);

在控制器上

var mongoose = require(‘mongoose’); var User = mongoose.model(‘User’); var user = new User({ nickname: username, acounts: username, password: password, sex: 1, country: ‘中国’, city: ‘阳江’, write: { create: Date.now(), update: Date.now() } });

如果有别的数据需要追加新字段,这时候该怎么追加?

回到顶部