Mongoose: Get full list of users

前端 未结 8 1123
遇见更好的自我
遇见更好的自我 2020-12-12 12:54

I have tried to use Mongoose to send the list of all users as follows:

server.get(\'/usersList\', function(req, res) {
    var users = {};

    User.find({},         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 13:33

    In case we want to list all documents in Mongoose collection after update or delete

    We can edit the function to some thing like this:

    exports.product_update = function (req, res, next) {
            Product.findByIdAndUpdate(req.params.id, {$set: req.body}, function (err, product) {
                if (err) return next(err);
                Product.find({}).then(function (products) {
                    res.send(products);
                    });
                //res.send('Product udpated.');
            });
        };
    

    This will list all documents on success instead of just showing success message

提交回复
热议问题