我在我的NodeJS REST项目中使用MongoDB和Mongoose ODM :
我的模型架构是:
var playerSchema = new mongoose.Schema({
name: String,
team: mongoose.Schema.Types.ObjectId
})
和服务器端:
app.post('/players', function(req, res) {
Players.find(function(err, players) {
res.json(players);
});
});
回应是:
...
{
"_id": "511a6010e6ca7b0fe0af02ff",
"name": "player-1",
"team": "511a53e2e6ca7b151c09ce8d"
}
...
但我想要类似的东西:
{
"_id": "511a6010e6ca7b0fe0af02ff",
"name": "player-1",
"team": {
_id: "511a53e2e6ca7b151c09ce8d"
name: "team-1"
}
}
我做错了什么?或者我还没有真正理解 ObjectId?
谢谢!