How to use 'populate' in Mongoose to get referenced data?
Code Playground
JavaScript (V8)
Loading...
Console Output
// Output will appear here...
// For React: ReactDOM.createRoot(rootElement).render(<App />);
// For React: ReactDOM.createRoot(rootElement).render(<App />);
Recommended Answer
js
const story = await Story.findOne({ title: 'Casino Royale' })
.populate('author') // 'author' is a ref in the schema
.exec();
console.log(story.author.name);