0

I'm doing a small-scale school project where I need to 'create an app' that manages a list of contacts. I'm really new to Nodejs and mongodb and sadly I cannot find any answer in the internet.

I'm trying to delete a record from a document, by debugging I know that the data (id) is sent correctly to the server.

 router.delete('/contact/:id', (req, res, next) => {
    db.contacts.deleteOne
       ({_id: mongojs.ObjectId(req.params.id)
    }).then(res => {
        console.log('deleted ' + res);
        res.status(200)
        .json({message: 'Deletion successful! '})
    });
});

Thank you very much :)

1 Answer 1

2

From your code, I guess you're using mongojs, mongojs doesn't contain a deleteOne method, so you have to rely on the provided API for that purpose by using :

db.collection.remove(query, [justOne], [callback])

More details on mongoJs official documentation Here

Sign up to request clarification or add additional context in comments.

1 Comment

yeah, i was following along a video that didn't put too much info on the differences, well, a rookie's mistake i guess! thank you very much :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.