Help Needed For - Delete Many Documents with model.remove()

Tell us what’s happening:
I don’t know what I’m doing wrong but my code matches the one listed on the guide page, but it always fails. I’ve tried watching tutorials videos to pass, but it still fails. I also get a warning and a SyntaxError message in the console after I submit it. Help please.

My Code

require('dotenv').config();

const mongoose = require('mongoose');

const mySecret = process.env['MONGO_URI']

mongoose.connect(process.env.MONGO_URI);

const Schema = mongoose.Schema;

var personSchema = new Schema({
   name : { type: String, required: true }, 
   age : Number, 
   favoriteFoods : [String]
});

var Person = mongoose.model('Person', personSchema);

var createAndSavePerson = function(done) {
  let janeFonda = new Person({
    name: "Jane Fonda", 
    age: 84, 
    favoriteFoods: ["eggs", "fish", "fresh fruit"]
  });

  janeFonda.save(function(err, data) {
    if (err) return console.error(err);
    done(null, data)
  });
};

var arrayOfPeople = [
  {name: "Bob", age: 74, favoriteFoods: ["baked potatoes"]},
  {name: "Sam", age: 76, favoriteFoods: ["chicken"]},
  {name: "Robert", age: 78, favoriteFoods: ["grapes"]}
];

var createManyPeople = function(arrayOfPeople, done) {
  Person.create(arrayOfPeople, function (err, people) {
    if (err) return console.log(err);
    done(null, people);
  });
};

var findPeopleByName = function(personName, done) {
  Person.find({name: personName}, function (err, personFound) {
    if (err) return console.log(err);
    done(null, personFound);
  });
};

var findOneByFood = function(food, done) {
  Person.findOne({favoriteFoods: food}, function (err, data) {
    if (err) return console.log(err);
    done(null, data);
  });
};

var findPersonById = function(personId, done) {
  Person.findById(personId, function (err, data) {
    if (err) return console.log(err);
    done(null, data);
  });
};

const findEditThenSave = (personId, done) => {
  const foodToAdd = 'hamburger';

  Person.findById(personId, (err, person) => {
    if(err) return console.log(err); 

    person.favoriteFoods.push(foodToAdd);

    person.save((err, updatedPerson) => {
      if(err) return console.log(err);
      done(null, updatedPerson)
    })
  })
};

const findAndUpdate = (personName, done) => {
  const ageToSet = 20;

  Person.findOneAndUpdate({name: personName}, {age: ageToSet}, {new: true}, (err, updatedDoc) => {
    if(err) return console.log(err);
    done(null, updatedDoc);
  })
};

var removeById = function(personId, done) {
  Person.findByIdAndRemove(
    personId,
    (err, removedDoc) => {
      if(err) return console.log(err);
      done(null, removedDoc);
    }
  ); 
};

const removeManyPeople = (done) => {
  const nameToRemove = "Mary";
  Person.remove({name: nameToRemove}, (err, response) => {
    if(err) return console.log(err);
    done(null, response);
  })
};

const queryChain = (done) => {
  const foodToSearch = "burrito";

  done(null /*, data*/);
};

/** **Well Done !!**
/* You completed these challenges, let's go celebrate !
 */

//----- **DO NOT EDIT BELOW THIS LINE** ----------------------------------

exports.PersonModel = Person;
exports.createAndSavePerson = createAndSavePerson;
exports.findPeopleByName = findPeopleByName;
exports.findOneByFood = findOneByFood;
exports.findPersonById = findPersonById;
exports.findEditThenSave = findEditThenSave;
exports.findAndUpdate = findAndUpdate;
exports.createManyPeople = createManyPeople;
exports.removeById = removeById;
exports.removeManyPeople = removeManyPeople;
exports.queryChain = queryChain;

Console Message

OPTIONS
POST
(node:340) [MONGODB DRIVER] Warning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse ()
at /home/runner/boilerplate-mongomongoose/server.js:346:29
at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/model.js:4920:18
at processTicksAndRejections (internal/process/task_queues.js:79:11)

Your project link(s)

solution: https://replit.com/@celestiaimoon/boilerplate-mongomongoose

Your browser information:

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

Challenge: Delete Many Documents with model.remove()

Link to the challenge:

Hey,
I had the same issue and the solution on this post worked for me: Delete Many Documents with model.remove() cant pass
It is more a workaround than a solution but if it can unblock you :slight_smile:

That helped me, thank you so much! :grinning: