Node seed.js error in vidly-api-node - MongoError: Unsupported OP_QUERY command: delete

^

I’m getting this error when trying to seed the database, anyone knows how to fix it?

1 Like

Did you find the solution of this probelm or not I am also getting the same error .

3 Likes

If anyone know the solution of above problem please tell

i did not find it :frowning:

So what to do with the problem ?

i did not anything…i could not find the solution

Could you paste the content of seed.js so someone can help debug this? Put it inside two sets of triple backticks (```) to make a code block. Then it will look like this:

function(param1, param2) {
  console.log(param1, param2);
}
1 Like

did you find the solution?

I am also stuck at this point in the course. This api has old stuff in it and i am using new versions of node. Can anybody help us with this ?

1 Like

If no one can paste the code as I requested, can someone at least tell me which course / video / exercise this is coming from?

Here’s my seed.js file (I also add user consts from this instruction):

const { Genre } = require("./models/genre");
const { Movie } = require("./models/movie");
const mongoose = require("mongoose");
const config = require("config");

const { User } = require("./models/user");

const data = [
  {
    name: "Comedy",
    movies: [
      { title: "Airplane", numberInStock: 5, dailyRentalRate: 2 },
      { title: "The Hangover", numberInStock: 10, dailyRentalRate: 2 },
      { title: "Wedding Crashers", numberInStock: 15, dailyRentalRate: 2 },
    ],
  },
  {
    name: "Action",
    movies: [
      { title: "Die Hard", numberInStock: 5, dailyRentalRate: 2 },
      { title: "Terminator", numberInStock: 10, dailyRentalRate: 2 },
      { title: "The Avengers", numberInStock: 15, dailyRentalRate: 2 },
    ],
  },
  {
    name: "Romance",
    movies: [
      { title: "The Notebook", numberInStock: 5, dailyRentalRate: 2 },
      { title: "When Harry Met Sally", numberInStock: 10, dailyRentalRate: 2 },
      { title: "Pretty Woman", numberInStock: 15, dailyRentalRate: 2 },
    ],
  },
  {
    name: "Thriller",
    movies: [
      { title: "The Sixth Sense", numberInStock: 5, dailyRentalRate: 2 },
      { title: "Gone Girl", numberInStock: 10, dailyRentalRate: 2 },
      { title: "The Others", numberInStock: 15, dailyRentalRate: 2 },
    ],
  },
];

const dataUsers = [
  { name: "Seed User", email: "[email protected]", password: "password" },
];

async function seed() {
  await mongoose.connect(config.get("db"));

  await User.deleteMany({});
  await Movie.deleteMany({});
  await Genre.deleteMany({});

  for (let genre of data) {
    const { _id: genreId } = await new Genre({ name: genre.name }).save();
    const movies = genre.movies.map((movie) => ({
      ...movie,
      genre: { _id: genreId, name: genre.name },
    }));
    await Movie.insertMany(movies);
  }

  for (let user of dataUsers) {
    await new User({
      name: user.name,
      email: user.email,
      password: user.password,
    }).save();
  }
  mongoose.disconnect();

  console.info("Done!");
}

seed();

Still have this " errmsg: ‘Unsupported OP_QUERY command: delete. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal’,
code: 352,
codeName: ‘UnsupportedOpQueryCommand’" o_O

And the course is Mastering React > section Calling backend services > Setting Up the Node Backend.

1 Like

At a glance, it looks like the version of Node.js you are using may not support MongoDB 6.0 which removed support for things like OP_QUERY (according to the link in the error). Here is the compatibility matrix for Node.js: https://www.mongodb.com/docs/drivers/node/current/compatibility/

It would appear that you need to use Node.js version 4.8 or greater to use this version of MongoDB. You can either upgrade Node.js (to 4.8) or downgrade MongoDB (to 5.0 or earlier).

Let me know if either of those threads get you anywhere - I will check back again later to do a little more digging.

Did you solve the problem ? how did you do it ?

Is the 20 video of calling Backend services of react, in the part when we put node seed.js in the console

I wanteed to try this, but I already have a new version of node

Can you share what version of node.js you are using? What is the output of this command at the terminal:

node -v

I have not tested this, but this appears to be the instructions for downgrading MongoDB 6.0 to an earlier version (5.0):

That seems like another reasonable option if there is some reason upgrading Node.js will not work.

Ok i will try it, thank !

By any chance do you have a different package version listed in the package.json file for your project?