mongodb - Node.js : which keys in req.body are present in schema -


when post request, want entries keys present in model's schema. example, if 'user' model's schema consists of 'name' , 'email' keys, iterate on req.body, want values 'name' , 'email' fields. how do that?

if understand question correctly, wanting have unspecified set of keys query mongo with, , return data keys.

if in fact case, using mongoose lodash/underscore:

var keys = _.keys(req.body);  user.find(req.body).select(keys.join(' ')).lean().exec(function(err, user {   if (err)     throw err;    res.send(user); }): 

that's assuming things req.body object , how keys match schema.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -