In the ‘Back end and API’'s certification, the lesson ‘Delete many documents with model.remove’ shows this error (below 1) when you run in Replit to validate with FCC website. I found this information on the MongoDB website about the depreciated (below 2) with the link to the page (below 3.) When I go to validate, FCC will not validate and Replit will not run the program. I am ALMOST certain the syntax is correct for the given lesson (below 4.) Please advise what I should do. All of this is very new to me and I might be missing something.
-
(node:956) [MONGODB DRIVER] Warning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
-
There are several deprecations in the MongoDB Node.js driver that Mongoose users should be aware of. Mongoose provides options to work around these deprecation warnings, but you need to test whether these options cause any problems for your application. Please report any issues on GitHub.
Summary
To fix all deprecation warnings, follow the below steps:
- Replace
update()
withupdateOne()
,updateMany()
, orreplaceOne()
- Replace
remove()
withdeleteOne()
ordeleteMany()
. - Replace
count()
withcountDocuments()
, unless you want to count how many documents are in the whole collection (no filter). In the latter case, useestimatedDocumentCount()
.
Read below for more a more detailed description of each deprecation warning.
-
const removeManyPeople = (done) => {
const nameToRemove = “Mary”;
Person.remove({name: nameToRemove}, (err, data) => {
if (err) {
return console.log(err);
}
done(null, data);
})
};
solution: https://replit.com/@andrewk4758/boilerplate-mongomongoose
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.66 Safari/537.36 Edg/103.0.1264.44
Challenge: Delete Many Documents with model.remove()
Link to the challenge: