I am trying to send recipe data such as title, description,prep time etc, but i keep getting this error Operation recipes.insertOne()
buffering timed out after 10000ms. I have tried almost every solution i have stumbled across but I still get this error. I have an auth service that works but this is the only part that doesnt want to work atm. Heres the core:
Recipe Controller
const Recipes = require('../models/recipe') const post = (req, res) => { const recipe = new Recipes(req.body); console.log(recipe) recipe.save(); try { res.status(201).send({ message: 'Recipe posted' }) } catch (err) { res.status(400).send({ err: console.error(), message: `${err}` }) } } module.exports = { post }
const mongoose = require('mongoose'); const recipeSchema = mongoose.Schema({ title: { type: String, required: ["Must Have Title"] }, category: { type: String, required: ['Must have selected a Category'] }, prepTime: { type: Number, required: ['Must have a Prep Time'], }, numberOfPeople: { type: Number, required: ['Must have a number of people'], }, description: { type: String, required: ['Must have a description'] } }) module.exports = mongoose.model('Recipes', recipeSchema, 'recipes')
const mongoose = require('mongoose'); let DSN = `mongodb://localhost:27017/recipes`; mongoose.connect( DSN, { useNewUrlParser: true, useUnifiedTopology: true }, err => { if (err) { return console.log('Could not connect to DB: ', err); } console.log('Successfully connected to database...'); });
The console.log shows the information is being captured but isn't being sent. I have tried with Recipes.create(req.body) and every other alternative I could find. Any help is appreciated
https://stackoverflow.com/questions/67359294/operation-insertone-buffering-timed-out-after-10000ms-node-js-mongoose May 03, 2021 at 01:30AM
没有评论:
发表评论