Why am I having trouble displaying and deleting in Mongo using Prisma (React app)?

Viewed 147

I use Node, Express, React, Mongo and Prisma to import a csv file in the database, display it on the frontend and delete all records in the db. It worked with one record and so I assumed it would work with the rest of the csv file (1000 records). But I get an error:

Invalid `prisma.movie.findMany()` invocation:
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawError { code: "unknown", message: "Command failed (CursorNotFound): cursor id 124425195753416376 not found)" } })
(node:2171) UnhandledPromiseRejectionWarning: Error: 

Invalid `prisma.movie.deleteMany()` invocation:
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawError { code: "unknown", message: "Command failed (CursorNotFound): cursor id 4391617472265441923 not found)" } })
    at cb (/Users/nwsursock/Sites/test-algot/backend/node_modules/@prisma/client/runtime/index.js:36378:17)
    at runMicrotasks ()
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async exports.deleteRequest (/Users/nwsursock/Sites/test-algot/backend/src/controllers/movie.controller.js:49:3)
(node:2171) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

My code is rather simple. I'm using the Prisma API in REST endpoints.

const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();

exports.createRequest = async (req, res) => {

  const movie = req.body.movie;
  console.log("============> importing", movie);
  const data = {
    name: movie.Name,
    genre: movie.Genre,
    descr: movie.Description,
    director: movie.Director,
    actors: movie.Actors,
    year: movie.Year,
    runtime: Number(movie["Runtime (Minutes)"]),
    rating: Number(movie.Rating),
    votes: Number(movie.Votes),
    revenue: Number(movie["Revenue (Millions)"]),
    score: Number(movie.Metascore),
  };
  const result = await prisma.movie.create({ data });
  console.log("============> imported", result);

  res.status(201).json({ message: "Movie correctly added!" });

};

exports.readRequest = async (req, res) => {
  try {
    const movies = await prisma.movie.findMany();
    res.status(200).json(movies);
  } catch (e) {
    console.log("======> Error:", e.message);
  }
};

exports.deleteRequest = async (req, res) => {
  await prisma.movie.deleteMany({});
  res.status(202).json({ message: "Table deleted!" });
};
1 Answers
Related