Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

Express 4.x 框架上 model和schema结合的文件怎么追加字段

$
0
0

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

他将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() } });

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


Viewing all articles
Browse latest Browse all 14821

Trending Articles