Last 2 exercises on Mongodb and Mongoose can't be solved

Tell us what’s happening:
I was unable to solve last two exercises i updated to the versions that are given in mongodb and mongoose tutorial and i still cant pass the test even the code seems fine.

Your code so far
require( ‘dotenv’ ).config();
const mongoose = require( “mongoose” );
const { Schema } = mongoose;

mongoose.connect( process.env.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true } );

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

} );

let Person = mongoose.model( ‘Person’, personSchema );

const createAndSavePerson = ( done ) => {
let darko = new Person( { name: ‘Darko’, age: 20, favoriteFoods: [‘Banana’, ‘Apples’] } );
darko.save( function ( err, data ) {
{
if ( err ) return console.log( err );
done( null, data );
}
} );

};

var arrayOfPeople = [
{ name: “Frankie”, age: 74, favoriteFoods: [“Del Taco”] },
{ name: “Sol”, age: 76, favoriteFoods: [“roast chicken”] },
{ name: “Robert”, age: 78, favoriteFoods: [“wine”] }
];

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

const findPeopleByName = ( personName, done ) => {
Person.find( { name: personName }, ( err, peopleFound ) => {
if ( err ) return console.log( err );
done( null, peopleFound );
}
);
};

const findOneByFood = ( food, done ) => {
Person.findOne( { favoriteFoods: food }, ( err, peopleFound ) => {
if ( err ) return console.log( err );
done( null, peopleFound );
} );
};

const findPersonById = ( personId, done ) => {
Person.findById( { _id: personId }, ( err, peopleFound ) => {
if ( err ) return console.log( err );
done( null, peopleFound );
} );
};

const findEditThenSave = ( personId, done ) => {
const foodToAdd = “hamburger”;
Person.findById( personId, ( err, person ) => {

// Array.push() method to add "hamburger" to the list of the person's favoriteFoods
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, updatedPersonAge ) => {
if ( err ) return console.log( err );
done( null, updatedPersonAge );
} );
};

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

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

const queryChain = ( done ) => {
const foodToSearch = “burrito”;
Person.find( { favoriteFoods: foodToSearch } )
.sort( { name: ‘asc’ } )
.limit( 2 )
.select( ‘-age’ )
.exec( function ( err, data ) {
if ( err ) return console.log( err );
done( null, data );

} );

};

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: Chain Search Query Helpers to Narrow Search Results

Link to the challenge:
https://www.freecodecamp.org/learn/back-end-development-and-apis/mongodb-and-mongoose/chain-search-query-helpers-to-narrow-search-results and https://www.freecodecamp.org/learn/back-end-development-and-apis/mongodb-and-mongoose/delete-many-documents-with-model-remove)

I saw those solutions but they do not work for me i have the versions of mongodb and mongoose the same as in tutorial. I tried through heroku and also i have tried submitting localhost:3000 but the result is the same. This is the error in terminal :

Your app is listening on port 3000
OPTIONS
POST
(node:9228) DeprecationWarning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

I have tried instead of person.remove to use deleteMany and the result is the same.
also node --trace-deprecation does nothing

darkosel3/MongoDb (github.com)

I updated to the version in the tutorial and this is the error.


And when i turn my mongo_uri into string it shows this

darkosel3/MongoDB2 (github.com)

Yes i havee tried but nothing works

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.