I want to track the number of connection a specific user makes using mongodb and node.js but I can't find the right way to do it
I have a database of users, each user has a document with a set limitation of how many pages open at the same time he can have but I can't track it. I tried using Socket.io but I couldn't find a way to assign different connections from different devices to the same account.
(I simplified the function, I don't actually save the code like this)
app.get('/', async (req, res) => {
if (req.activationCode == '123') {
return User.findOne({
activationCode: '123'
}, function (err, doc) {
doc.active_users++;
doc.save();
}).then(docs => {
res.render('index', {
settings: docs.settings
})
})
}
res.render('login')
});
And I also have this code
io.on('connection', function (socket) {
console.log('A user connected');
socket.on('disconnect', function () {
console.log('A user disconnected');
});
});
Thanks a lot!