I am having an issue inserting a document into MongoDB. I am able to successfully connect to the database, but when i try to insert a new document i get the following error:
Error: Operation `bootcamps.insertOne()` buffering timed out after 10000ms
[nodemon] app crashed - waiting for file changes before starting...
URI Connection string:
MONGO_URI=mongodb+srv://blahblah:<password>@cluster0.ohppr.mongodb.net/devcamper?retryWrites=true&w=majority&appName=Cluster0
db.js
const mongoose = require('mongoose')
const connectDB = async () => {
const conn = await mongoose.connect(process.env.MONGO_URI)
console.log(`MongoDB Connected: ${conn.connection.host}`.cyan.underline.bold)
}
module.exports = connectDB
MongoDB Network:
server.js
const express = require('express')
const dotenv = require('dotenv')
const connectDB = require('./config/db')
// Load env variables.
dotenv.config({ path: './config/config.env' })
// Connect to DB
connectDB()
bootcamp.js
const Bootcamp = require('../models/Bootcamps')
// @desc Create new bootcamp
// @route POST /api/v1/bootcamps
// @access Private
exports.createBootcamp = async (req, res, next) => {
//console.log(req.body)
//res.status(201).json({success: true})
const bootcamp = await Bootcamp.create(req.body);
res.status(201).json({
sucess: true,
data: bootcamp
})
}
if i comment out the following lines of code everything runs ok.
const bootcamp = await Bootcamp.create(req.body);
res.status(201).json({
sucess: true,
data: bootcamp
})
}
Postman