Construct a mongodb query update for embedded documents.
Works great with mongoose.
$ npm install emquery
$ node example.js
const emquery = require('emquery');
const UserModel = require('../models/user');
app.put('/users/:id', function updateUser(req, res, next) {
const updates = {
$set: emquery(req.body);
};
User.findByIdAndUpdate(user._id, updates, function(err, user) {
if(err) return next(err);
res.json(user);
});
});
Pass in the object to parsed to a query.
MIT