I would like to use .populate() with Sails js and MongoDB and so I did something like this:
I am using the latest version of Sails and MongoDB and Node.
My models look like:
// User.js
module.exports = {
attributes: {
name: {
type: 'string'
},
pets: {
collection: 'pet',
via: 'owner'
}
}
};
// Pet.js
module.exports = {
attributes: {
name: {
type: 'string'
},
owner: {
model: 'user'
}
}
};
And I used the following which is the same as the documentation:
User.find()
.populate('pets')
.exec(function(err, users) {
if(err) return res.serverError(err);
res.json(users);
});
But I get the following output:
[
{
"pets": [],
"id": "58889ce5959841098d186b5a",
"firstName": "Foo",
"lastName": "Bar"
}
]