我的Express + Node后端有以下功能来保存新的“结果”
var saveResult = function(username, result, callback){
var resultItem = new models.Round_Results({
round: mongoose.Types.ObjectId(result.round),
selection: 10,
time: 15
});
models.User.findOne({username: username}, function(err, user){
user.results.push(resultItem);
user.save(function(err, result){
if (err)
console.log("ERROR! " + err);
else
callback(result);
});
});
}
Schemas等一切都很好。
问题是,我期待如果我从前端推出相同的“结果”10次,我会在数组中的每个对象中看到所有相同的数据。
但事实并非如此。我已经POST
了3次以下数据,这是我的结果:
{round: 555ec731385b4d604356d8e5, selection: 1, time: 20}
服务器的结果:
{
"result": {
"_id": "5570fe093beeefcc80f44439",
"username": "moe",
"password": "moe",
"__v": 10,
"firstname": "Da Real Moe",
"results": [
{
"_id": "557225ba7588942040301b8c",
"time": 15,
"selection": 10,
"round": "557225ba7588942040301b8b"
},
{
"_id": "557225bd7588942040301b8e",
"time": 15,
"selection": 10,
"round": "557225bd7588942040301b8d"
},
{
"_id": "557225bf7588942040301b90",
"time": 15,
"selection": 10,
"round": "557225bf7588942040301b8f"
}
]
}
}
round
怎么可能不同?我每次给它同样的回合!