填充数据后,我得到的结果与预期不符。
示例:
//User.js Model
module.exports = {
attributes: {
//"id" attribute is here primary key by default
schools: { collection: 'School', via: 'id' },
name: { type: 'String', trim: true, required: true }
}
}
这是我的School.js
//School.js Model
module.exports = {
attributes: {
//"id" attribute is here primary key by default
name: { type: 'String', trim: true, required: true },
}
}
我的用户实体数据如下所示:
//User document in MongoDB
{
_id: 1,
name: "Foo",
schools: [1,2,3]
}
我的学校实体数据如下所示:
//School documents in MongoDB
{
_id: 1,
name: "School 1"
}
{
_id: 2,
name: "School 2"
}
{
_id: 3,
name: "School 3"
}
现在我想填补学校。我是这样做的:
User.find().populate("schools").exec(function(err, res){ console.log(res[0]) });
这就是我得到的结果:
{
schools: [Getter/Setter],
name: "Foo",
id: 1
}
预期:
{
schools: [
{id: 1, name: "School 1"},
{id: 2, name: "School 2"},
{id: 3, name: "School 3"}
],
name: "Foo",
id: 1
}
我如何获得预期的结果?
我使用MongoDB作为数据存储。
版本:
Sails.js:v0.10.0-rc5
水线:v0.10.0-rc7
sails-mongo:0.10.0-rc2
答案 0 :(得分:1)
这些是使用console.log
时的预期结果!如果要查看展开的对象,请执行以下操作:
console.log(res[0].toObject());