New to mongoose & node.
I can't figure out if mongoose document.save method is async. I'm assuming that it is, since it works even when not connected. Is there a way to tell when the document is actually saved (callback)?
The connect() method provided by the Mongoose supports both JavaScript promises and async-await syntax.
You are most likely to accidentally re-execute queries in this way when mixing callbacks with async/await. This is never necessary and should be avoided. If you need a Query to return a fully-fledged promise instead of a thenable, you can use Query#exec().
save() is a method on a Mongoose document. The save() method is asynchronous, so it returns a promise that you can await on.
Mongoose | save() Function The save() function is used to save the document to the database. Using this function, new documents can be added to the database.
yep, it's async. You can use the 'error' parameter to see if there was an error during saving.
http://mongoosejs.com/docs/api.html#model_Model-save
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With