These are chat archives for Automattic/mongoose

15th
May 2015
Erinç Fırtına
@EricMcRay
May 15 2015 08:36
what is the best approach to update a model from request body? How can I prevent update some fields?
All people in my company using FindOneAndUpdate but I think it is a force update directly to mongodb. It bypasses all mongoose magic right?
Sebastian Van Sande
@seppevs
May 15 2015 12:52
Does anyone know I can unregister a plugin?
I use a timestamp plugin (to add createdAt & updatedAt dynamically), but I want to disable it when I run my tests (because will provide these timestamps myself during testing)
Valeri Karpov
@vkarpov15
May 15 2015 14:33
@EricMcRay structure your data so all the things you want to update are under 1 or 2 sub-docs, e.g. when you only want users to be able to update their profile from a route just do user.profile = req.body.profile and that will only update fields under profile
and findOneAndUpdate() bypasses some mongoose magic but not all of it. findOneAndUpdate() still does casting and you can turn on update validators in 4.0 to run schema validators on $set and $unset ops
@seppevs no good way to do that atm. Best way would be to have your schema be returned by a function and have it conditionally add the plugin
Pedro Machado Santa
@pedrosanta
May 15 2015 16:11
Hi there. Any good suggestion on Express + Mongoose project structure? A seed project, boilerplate or so?
Sebastian Van Sande
@seppevs
May 15 2015 16:23
I solved it in another way. I do a 'real' update now in my tests so the updatedAt is changed.
Valeri Karpov
@vkarpov15
May 15 2015 16:55
@pedrosanta I have a few examples like https://github.com/vkarpov15/lean-mean-nutrition-sample up on github. They're slightly out of date with how I like to build projects nowadays but if you're looking for real examples that's a good place to start
Pedro Machado Santa
@pedrosanta
May 15 2015 17:04
Thanks @vkarpov15.
Probably I'm gonna go with something like Mean.js...
Valeri Karpov
@vkarpov15
May 15 2015 18:53
mean.js is pretty sweet. StrongLoop's also a pretty good option if you're looking for scaffolding
although IMO I'd recommend not using scaffolding until you've at least built one app on your own :)