mongodb/mongojs won't update with put

47 Views Asked by At

I am working on a simple CRUD app using MEAN stack and I was testing my server to ensure that I could perform requests on my mongodb database. I was able to perform GET, POST and DELETE requests but when I use postman to perform a PUT request, I get this as a response

{
    "driver": true,
    "name": "MongoError"
}

Here is my code for performing PUT requests:

router.put('/todo/:id', function (req, res, next) {
    var todo = req.body;
    var updTodo = {};

    if(todo.title){
        updTodo.title = todo.title;
    }
    if(!updTodo){
        res.status(400);
        res.json({
            error : "Bad Data"
        });
    } else  {
        db.todos.update(
            {_id : mongojs.ObjectId(req.params.id)}, updTodo, {}, function (error, todo) {
            if (error){
                res.send(error);
            }
            res.json(todo);
        });
    }
});

I'm new to Express so I'm not entirely sure what I'm doing wrong here.

Edit: This is what the request looks like:Screenshot

0

There are 0 best solutions below