javascriptnode.jsmongodbexpress

Error Message from MongoDB "Operation `disneys.insertOne()` buffering timed out after 10000ms"


I'm currently creating a new API with MongoDB and Express, and I'm currently having this issue:

"Operation disneys.insertOne() buffering timed out after 10000ms."

I'm currently using route.rest to test my API.

However, I don't know what I'm currently doing wrong, could someone take a look at my Github Repository ?

This is the way that I setup my API calls:


const express = require("express");
const router = express.Router();
const Disney = require("../models/disneyCharacter");

// Getting all character

router.get("/", async (req, res) => {
  try {
    const character = await Disney.find();
    res.json(character);
  } catch (err) {
    res.status(500).json({ message: err.message });
  }
});
// Getting one Character
router.get("/:id", getCharacter, (req, res) => {
  res.json(res.character);
});

// Creating new Character
router.post("/", async (req, res) => {
  const character = new Disney({
    name: req.body.name,
    details: req.body.details,
  });
  try {
    const newCharacter = await character.save();
    res.status(201).json({ newCharacter });
  } catch (err) {
    res.status(400).json({ message: err.message });
  }
});

// Updating one character
router.patch("/:id", getCharacter, async (req, res) => {
  if (req.body.name != null) {
    res.character.name = req.body.name;
  }
  if (req.body.details != null) {
    res.character.details = req.body.details;
  }
  try {
    const updateCharacter = await res.character.save();
    res.json(updateCharacter);
  } catch (err) {
    res.status(400).json({ message: err.message });
  }
});

// Deleting one character
router.delete("/:id", getCharacter, async (req, res) => {
  try {
    await res.character.remove();
    res.json({ message: "Deleted character" });
  } catch (err) {
    res.status(500).json({ message: err.message });
  }
});

async function getCharacter(req, res, next) {
  let character;
  try {
    character = await character.findById(req.params.id);
    if (character == null) {
      return res.status(404).json({ message: "Cannot find character" });
    }
  } catch (err) {
    return res.status(500).json({ message: err.message });
  }

  res.character = character;
  next();
}

module.exports = router;


My parameters are the following:

const mongoose = require("mongoose");

const disneyCharacter = new mongoose.Schema({
  name: {
    type: String,
    required: false,
  },
  details: {
    type: String,
    required: false,
  },
  subscribeDate: {
    type: Date,
    required: true,
    default: Date.now,
  },
});

module.exports = mongoose.model("Disney", disneyCharacter);

This is my API call:


Post http://localhost:3000/disneyCharacter
Content-Type: application/json

{
    "name": "Mickey Mouse",
    "details": "First Character from Disney"
}

Please let me know if you have any other questions or concerns.


Solution

  • try this out How to solve Mongoose v5.11.0 model.find() error: Operation `products.find()` buffering timed out after 10000ms"

    Also, your API call seem to have a problem, It should be disneyCharacters instead of disneyCharacter.

    Also, probably setup a local database first instead of using process.env.DATABASE_URL.