下面有一个名为User的模型。
var mongoose = require('mongoose');<br> var Schema = mongoose.Schema;
var User = new Schema({<br>
firstName : {type: String, unique: false},<br>
lastName : {type: String, unique: false},<br>
loginName : {type: String, unique: true},<br>
password : {type: String, unique: false},<br>
email : {type: String, unique: false},<br>
software: {<br>
type : Schema.ObjectId,<br>
ref : Software<br>
}<br>
});
module.exports = mongoose.model('User', User);
当启动User的对象时,如何为&#34;软件&#34;提供价值。以上?
var user1 = new User({<br>
firstName: req.body.firstName,<br>
lastName: req.body.lastName,<br>
loginName: req.body.loginName,<br>
password: req.body.password,<br>
email: req.body.email,<br>
??????<br>
});<br>
答案 0 :(得分:0)
只需从客户端发送软件架构数据的_id,
像这样software : "50906d7fa3c412bb040eb578"
(仅限字符串)然后你使用req.body.software获得价值
var user1 = new User({
firstName: req.body.firstName,
lastName: req.body.lastName,
loginName: req.body.loginName,
password: req.body.password,
email: req.body.email,
software:req.body.software
});