These are chat archives for Automattic/mongoose

9th
Jan 2016
Earl Lewis
@elewis33
Jan 09 2016 00:38
@vkarpov15, what to you mean that "for each of the fields you can DRY it up with a loop"? I understand DRY, but are you talking about some kind of generalized loop that you can apply to any model?
that's an intriguing idea and would like to know more, if that's what you meant
@dbelieves, what you are asking can be solved with what's called "dot-notation". If the fields are lower in the hierarchy of the model simply separate them with a dot, like @vkarpov15 suggested.
ah, missed your message where you said you got it working. doh...
Dipankar Arhat
@dbelieves
Jan 09 2016 12:47
@elewis33 , i solved it by doing this
var doc = new House({

latitude: req.body.latitude,
longitude: req.body.longitude,
address: req.body.address,
locality: req.body.locality,
city: req.body.address,
state: req.body.state,
desc: req.body.desc,
.
.
.
Valeri Karpov
@vkarpov15
Jan 09 2016 15:49
@elewis33 const map = { 'latitude': 'meta.latitude', 'name': 'profile.name' }; _.each(map, function(dest, src) { _.set(doc, dest, _.get(req.body, src)); }); would be the general idea
so you just declare a mapping of field names in req.body to the place where they need to go in the doc