These are chat archives for Automattic/mongoose

Apr 2015
Alex Hatzipanis
Apr 07 2015 02:59
I'm quite new to Mongoose so I'm looking for what might be an easier way to do the following. I'm doing a findOneAndUpdate to set a couple of fields (hasSubscription mainly) to true and in the callback function we then create the subscription via PayPal. That returns some data that I then want to add to another field in the model. Do I call another findOneAndUpdate inside the callback or is there a better way? Any help most appreciated.
Stephan Kristyn
Apr 07 2015 09:13
@valier thanks for this link - - I hoped that we could validate the browser data against the schema residing on the server, without having to redundantly declare it a new.
Valeri Karpov
Apr 07 2015 13:44
@hatzipanis I'd recommend you do another findOneAndUpdate(). IMO that's the correct pattern - findOneAndUpdate() before subscribing to paypal to say "trying to add subscription" and after success to say "yep, according to paypal this user is now subscribed"
@nottinhill glad you found it useful :)
Derick Bailey
Apr 07 2015 19:18
hi - i had previously been using to get a "construct" hook in my schema, because i need to ensure some things are run whenever a document instance is created. however, with upgrading to mongoose v4, this plugin no longer works. does anyone know how to get this working again? i have code in my construct that must run when creating the model instance, and the "init" hook only works when loading the document from the database :(
Alex Hatzipanis
Apr 07 2015 21:05
@vkarpov15 Thanks for your reply. Is this what is known as callback hell? I see that around a bit. Although a mild case of it?