I want to find the number of visitors. So I just created a collection with the count
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Visitor = new Schema({
count: { type: Number, default: 0 },
});
module.exports = mongoose.model('visitor', Visitor);
Now I want to increment the value of count where the route /backend/visitors
is calling
const Visitor = require('../models/Visitor');
router.route('/backend/visitors').get(function (req, res, next) {
const visitor = new Visitor({
count:1,
});
Visitor.update({}, { __v: 0 })
.then(users => {
console.log(users)
try {
visitor
.save()
.then(visitor => {
res.send(visitor);
})
}
}
)
});
I dont know how to increment a value of count in database, after that i want to send a response of count to the page like res.send(count)