you can use save method instead of insertOne
first instantiate your object by adding new databaseCollection(newService)
. and after that call save method to insert your collection
Use res.json
instead of res.send
to enforce Content-Type
to be of JSON type
Your code should look like this:
app.post("/service", async (res, req) => {
const newService = req.body;
try {
const service= await new databaseCollection(newService);
const savedService=await service.save()
res.status(200).json(savedService);
} catch (err) {
res.status(500).json(err);
}
});
* Be the first to Make Comment