'Mongo db not returning result after sending a post request
I am new too expressjs and mongodb. I am trying to add data to a collection in my database using a post request in express but it is now working. Here is my code.
MongoClient.connect(connectionString, { useUnifiedTopology: true })
.then(
client => {
console.log("Connected to the database")
const db = client.db('star-wars')
const quotesCollection = db.collection('quotes')
app.post('quotes/', (req, res) => {
quotesCollection.insertOne(req.body).then(
result => {
console.log(result)
res.redirect('/')
}
).catch(error => console.error(error))
})
}
).catch(error => console.error(error))```
It is meant to log result back to the console but nothing is happening
Solution 1:[1]
Routes should start with /quotes not quotes/.For that your app cant access the post request.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dharman |
