[Vuejs]-Vue update data within mongoose database and using axios call

0👍

When you do you GET request to your video route, in your route logic, you should be able to use Mongoose count. Here is what that route might look like:

var Router = require('express').Router();
var mongoose = require('mongoose');
var Video = mongoose.model('Video');

Router.get('/videos', function(req, res) {
    var response = {};

    Video.find({}, function(queryErr, videos) {
        if (!queryErr) {
            response.videos = videos;

            Video.count({}, function(countErr, count) {
                if (!countErr) {
                    response.count = count;
                    res.status(200).send(response);
                } else {
                    res.status(500).send(countErr);
                }
            });
        } else {
            res.status(500).send(queryErr);
        }
    });
});

module.exports = Router;

Here is a question about Mongoose count on Stack Overflow.

Leave a comment