Am getting this error. MongoServerError: user is not allowed to do action [remove] on [shoeDatabase.users]

78 views Asked by At

This error is what I find. user is not allowed to do action MongoServerError: user is not allowed to do action [remove] on [shoeDatabase.users],

import express from "express";
import User from "./Models/UserModel.js";
import users from "./data/users.js";
const ImportData = express.Router();

ImportData.post("/user", async (req, res) => {
  await User.remove({});
  const importUser = await User.insertMany(users);
  res.send({ importUser });
});

export default ImportData;
1

There are 1 answers

0
Michal Miky Jankovský On

solution for your error is :

  • change the rights in the database
  • your script has not rights to remove any user

there are other problems to address:

  • await User.remove({}); will remove all present users... are you sure?
  • where are users originated from? (should be parsed from req and are not)