MongoDB and Mongoose - Delete Many Documents with model.remove()

Tell us what’s happening:
I can’t solve that challange and i get back error that say that is collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.

Your project link(s)

solution: Join ARMMM96's "boilerplate-mongomongoose" - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: MongoDB and Mongoose - Delete Many Documents with model.remove()

Link to the challenge:

The original replit boilerplate has the following dependencies in package.json:

  "dependencies": {
    "body-parser": "^1.15.2",
    "dotenv": "^8.2.0",
    "express": "^4.12.4",
    "mongoose": "^5.11.15"
  },

For some reason, your package.json has a different version of mongoose (which is causing the error you are seeing). Also, I see an extra package named validator. Did you change the mongoose version and add this extra package?

@ARMMM96 @Sky020

FYI - I just did a test and noticed that Replit seems to be automatically adding the validator package on its own.

Why is Replit now adding extra packages?

@RandellDawson I was unable to reproduce an automatic package addition.

Do you remember doing anything specific?

  1. Fork this user’s replit.
  2. Delete package-lock.json file
  3. Delete node_modules folder
  4. Click Run

You should then see validator package being added.

Maybe this user cloned this a while back before we got rid of the .replit and replit.nix files.

You are correct though. If I just use the current starter boilerplate, I do not get the extra packages and package-lock.json shows the correct version of mongoose.

@ARMMM96 I suggest starting over clicking on the replit starter link again. Let us know if you run into any further problems.

I removed the original mongoose and i have installed the older version according to one of the answers here, but it didn’t work as well,
I didn’t install validator but what is the problem with other packages, what is the correlation with mongoose ? why it won’t do the delete request to the data base?

no i didn’t do that i just returned back to older version of mongoose

Something about the replit is corrupt. Just start a new version of the project by clicking on the starter link again. The reason it was not deleting is because for whatever reason, the replit was ignoring the mongoose version in the package.json file and installing a newer version where the remove method is deprecated.

I’ve created a new project but still the same problem with Model.remove() method

Link : Join ARMMM96's "boilerplate-mongomongoose (1)" - Replit

@Sky020 Actually, now I am seeing a different issue.

I click on the replit starter link for the mongoose section.

I add my MONGO_URI to the secrets.

I copy/paste my “working” code from my local repo of the project into the myApp.js on the replit.

When I click Run I get:

Error: Cannot find module '/home/runner/boilerplate-mongomongoose-4/index.js'
Require stack:
- /nix/store/29fdcv1yhlll61ml8a31qdkrbprxd7gs-prybar-nodejs-0.0.0-67f7a00/prybar_assets/nodejs/module-context-hook.js
- /tmp/prybar-nodejs-2819920328.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)

in the replit Console. I see the same thing in the user’s new replit.

EDIT: I figured out what was causing the error I was seeing. I guess now you have to click on Done in the preview pane for the Run button to work correctly. Is that in any instructions for users?

I have started the project again all actions are working
but the only function that it dons’t work is Model.remove() or emoveManyPeople
is why the site don’t want to accept it ?

I see this error

E11000 duplicate key error collection: test.people index: name_1 dup key: { name: “Mary” }

I think you may have had the name in the schema set to unique at one point. Delete the collection and try again.


If I use your current code with my own DB it passes the test.