MongoDB and Mongoose - Create Many Records with model.create()

I have read previous posts and the solutions are not working for me. I continue to get a callback error. Does anyone know why?

const personSchema = new mongoose.Schema({
name: {
type: String,
required:true
},
age: {
type: Number,
required:true
},
favoriteFoods: {
type: [String]
}
})
let Person = mongoose.model(‘Person’, personSchema );

const createAndSavePerson = (done) => {
const maryKate = new Person ({
name: “Mary Kate”,
age: 42,
favoriteFoods: [“apple”,“pear”,“banana”]
});
maryKate.save((err, data) => {
if (err) return console.error(err);
done(null, data)
});
console.log(${maryKate});
}

I know the image of your package.json says you are using Mongoose V5 but I don’t think you are. That version does support callbacks (and V6). Starting with V7 the callback support was dropped.

https://mongoosejs.com/docs/7.x/docs/migrating_to_7.html#dropped-callback-support


What do you get if you run npm view mongoose from the terminal in the root folder?

You can run npm rm mongoose and then npm i mongoose@^5.11.15 (the challenges should likely also work with 5.13.21 but you will have to test it).

:scream: So True! I ran npm i mongoose@^5.11.15.

I now seem to have an Atlas related authorization error. I tried adjusting some settings but nothing changed and I don’t know if thats the issue.


Try adding a DB name to the connection string.

mongodb+srv://name:password@cluster0.blabla.mongodb.net/yourDatabaseName?retryWrites=true&w=majority

That worked! Don’t know why. Thank you!

I believe it is a limitation of the free tier

I didn’t really find a good docs link