I built an API that can fetch all data from a table, but within this table there is an object ID reference to a user.
Table 1 - Story | Table 2 - User
api.get('/all_stories', function(req, res) {
Story.find({}, function(err, stories) {
if (err) {
res.send(err);
return;
}
res.json(stories);
});
});
This API retrieves all the data within the Story table and returns it as JSON.
creator: { type: Schema.Types.ObjectId, ref: 'User' },
content: String,
created: { type: Date, default: Date.now() }
How can I use ref: 'User' to find and display other data columns inside the User table? Or maybe even return it as JSON?