This is my first Stack overflow posting.I’m new to the MERN stack and I’m having trouble POSTing raw data to my web application from postman.
The data:
{
"title": "Situps",
"load": 0,
"reps": 50
}
the error I get when i send a POST request is:
{
"error": "Operation `workouts.insertOne()` buffering timed out after 10000ms"
}
This is the .js file i think may be the culprit:
const express = require('express')
const Workout = require('../models/workoutModel')
const router = express.Router()
// Get all workouts
router.get('/', (req, res) => {
res.json({mssg: 'Get all workouts'})
})
// Get single workout
router.get('/:id', (req, res) => {
res.json({mssg: 'Get a single workout'})
})
// Post a new workout
router.post('/', async (req, res) => {
const {title, load, reps} = req.body
try {
const workout = await Workout.create({title, load, reps})
res.status(200).json(workout)
} catch (error) {
res.status(400).json({error: error.message})
}
})
// Delete a workout
router.delete('/:id', (req, res) => {
res.json({mssg:'Delete a workout'})
})
// Update a workout
router.patch('/:id', (req, res) => {
res.json({mssg:'Update a workout'})
})
module.exports = router
Bilal Mohamadzadeh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I figured it out. The issue was i forgot to enter my password into the password field when creating an environment variable to connect my database to my application.
mongodb+srv://Name:[email protected]/?retryWrites=true&w=majority&appName=MERNapp
“password” should have been changed to my chosen mongo password
Bilal Mohamadzadeh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.