0
我有這樣的「用戶」的模式在哪裏存儲的朋友,這個朋友有一些選項貓鼬填入命名和結構
// Prepare schema
var schema = new db.Schema({
friends: [{
active : Boolean,
user : { type: db.Schema.ObjectId, ref: 'user' },
options : [{ type: db.Schema.ObjectId, ref: 'friend_option' }],
}],
image: { type: db.Schema.ObjectId, ref: 'file' },
password: {
type: String,
select: false
},
email: String,
name: String,
udid: [{
device: String,
udid: String
}],
created_on: Date
});
在這裏我得到一個用戶與他的朋友們
var friendQuery = User.find({_id:req.params.id});
friendQuery.select('friends');
friendQuery.populate({ path: 'friends._id', model: 'user', select:'_id name' });
friendQuery.exec(
function(err, user) {
if (err)
res.send(err);
res.send(user);
});
我的問題是,爲什麼結果與我的模型名稱不同?爲什麼朋友 - > _ id - > _ id而不是朋友 - >用戶 - > _ id?
friends": [
{
"_id": {
"_id": "58025664c154929d3207b232",
"name": "User 1"
},
"options": [
],
"active": false
},
{
"_id": {
"_id": "580257e1e3cd4fc7326fa97b",
"name": "User 2"
},
"options": [
],
"active": false
}
]
另一種選擇,這種解決方案適用於假設的大應用程序嗎?