Reputation: 1
I'm new in server side and maybe understand the concept of adding data to db wrong. I want to add a user that comes from axios.post to specific groupId parameter but when I do get requests on the postman I see that it adds the user to all the groups I have but not only to the matched one in the route.
Here are the post and get handlers for the route:
router.get('/groups/:groupId/users',function(req,res, next){
Group.findOne({groupId: req.params.groupId}).then(function(group) {
User.find({}).sort({_id: -1}).limit(15).then(function (user) {
res.send(user);
}).catch(next);
})
});
router.post('/groups/:groupId/users', function(req, res, next){
Group.findOne({groupId: req.params.groupId}).then(function(group) {
User.create(req.body).then(function (user) {
res.send(user);
})
}).catch(err => {
console.log(err)
});
});
postman request shouldn't be added
Upvotes: 0
Views: 33