我试图创建一个使用MEAN.io体育事件管理系统的应用,因为它采用了模块化的方法,也有来自于骨架应用不同的包,比如system,users,access.我想要做的是创建一个新的包players,它应该扩展用户包.播放器架构将包含额外的字段section和teams.那么如何扩展users包中的用户架构players?
我在 mongoose 中定义了一个架构,如下所示:
var VolunteerSchema = new Schema ({
......
other fields
.....
preferLocations:[{
type: Schema.ObjectId,
ref: 'Location'
}]
.....
});
Run Code Online (Sandbox Code Playgroud)
我正在使用volunteer.save()方法来更新模型。
在更新volunteer模型时,我收到如下错误:
{ [DivergentArrayError: For your own good, using `document.save()` to update an
array which was selected using an $elemMatch projection OR populated using skip,
limit, query conditions, or exclusion of the _id field when the operation resul
ts in a $pop or $set of the entire array is not supported. The following path(s)
would …Run Code Online (Sandbox Code Playgroud) 我正在使用 mean.io 制作体育赛事管理系统。我正在尝试使用 rest api 更新模型 Player,它从 mongoose 抛出此错误:
{ _id: 5411c79895d600440c698fa1,
email: 'abc@bcd.com',
name: 'James Bond',
username: 'james.bond',
games: [ 5411bd54786cfe2420f1e27a ],
teams: [],
roles: [ 'authenticated' ] }
[TypeError: Cannot read property '_id' of undefined]
PUT /api/players/5411c79895d600440c698fa1 500 199.402 ms - 36
Run Code Online (Sandbox Code Playgroud)
我还尝试从播放器中删除 _id 属性,但它也不起作用。我用来更新模型播放器的方法是:
exports.update = function(req, res) {
var player = req.player;
player = _.extend(player, req.body);
console.log(player);
Player.findOneAndUpdate(req.params.playerId, player,{new:true}, function (err, updatedPlayer) {
console.log(err);
if (err) {
return res.status(500).json({
error: 'Cannot update the player'
});
} …Run Code Online (Sandbox Code Playgroud)