Create and then populate?
See original GitHub issueIs it possible to do something like this…?
db.model('User').create({ name: 'John' }).populate('_company').exec(function(err, user) {
if (err) return next(err)
console.log(user)
// outputs user with populate user._company object from Company model
})
The only way I see it working now is…
db.model('User').create({ name: 'John' }, function(err, user) {
if (err) return next(err)
db.model('User').findById(user._id).populate('_company').exec(function(err, user) {
if (err) return next(err)
console.log(user)
// outputs user with populate user._company object from Company model
})
})
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Mongoose populate after save - node.js - Stack Overflow
You should be able to use the Model's populate function to do this: http://mongoosejs.com/docs/api.html#model_Model.populate In the save handler for book, ...
Read more >Mongoose v6.8.2: Query Population
In general, there is no way to make populate() filter stories based on properties of the story's author . For example, the below...
Read more >Mongoose's Model.Populate() - Medium
And like magic, we have created a unified object using 2 schemas, 2 models, and 2 collections. All of the steps are important...
Read more >Mongoose Populate() Method - GeeksforGeeks
In MongoDB, Population is the process of replacing the specified path in the document of one collection with the actual document from the ......
Read more >How to use Populate in Mongoose & Node.js
If no document is found to populate, then field will be null . ... We are going to create 3 collections with 3...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
try this
You can also do: