Deprecation Warning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead

I am getting this error on the final task of the MongoDB and Mongoose challenges and unfortunately cannot pass it.
I successfully passed the previous challenge that used the .remove method and my code to the final challenge seems to be correct as well (from what I can tell).
I have seen this issue being discussed in a number of other topics, but couldn’t find a solution… :confused:

Help is greatly appreciated!

[spoiler]
const removeManyPeople = (done) => {
  const nameToRemove = "Mary";
  Person.remove({name: nameToRemove}, function(err,data) {
    if(err) return done(err)
    done(null, data)
  })
};

const queryChain = (done) => {
  const foodToSearch = "burrito";
  Person.find({food: foodToSearch})
    .sort({name: -1})
    .limit(2)
    .select({age: 0})
    .exec(function(err,data) {
      if(err) return done(err)
      done(null, data)
    })
};
[/spoiler]

It’s “just” a warning. It basically just means stop using it and change to whatever the message is suggesting instead. Future versions may remove it, or may not, but you shouldn’t keep depending on deprecated features in the long run.

For the challenge, it is obviously testing for it so you can’t really do anything about it. The challenge would need to be updated.

2 Likes

Thanks for the answer!
Ok, so basically there is (at the moment) no way to pass this challenge?

Sorry for the late reply. I thought you were passing the challenge, are you not?

The message shouldn’t interfere with anything, like I said it’s an informational warning. As long as the version of the lib you are using still has the method it should work, which I assume it does.

1 Like

Yeah, unfortunately I’m not passing it, could have worded that better.
I am passing the previous challenge that uses the .remove method for which the error is showing up. In the last challenge, I don’t use the method, but now the error shows up for it and for some reason I don’t pass the challenge.
I will double check again, but from what I could tell my solution should work. Perhaps I missed some obvious mistake… :smiley:

Oh I thought the question was just for the challenge that uses .remove.


Make sure you are sorting correctly (I believe it should be ascending, not descending).

I would also recommend using the more explicit values for sort and select. Remembering that -1 and 0 does is harder than ascending/asc and "-age" (in my opinion).


Without seeing all the code it’s a little hard to know if, for example, it should be favoriteFoods or just foods.

1 Like

Oh… it was one of those mistakes again… :smiley:
It was indeed that I didn’t sort in the correct order and that for some reason I decided to write “food” instead of “favoriteFoods”.

Thanks a lot!

1 Like