Tell us what’s happening:
Hi can any one help me with these chalenge, i have reed a lot of topics, serched and noting
Your code so far:
/** # MONGOOSE SETUP #
/* ================== */
/** 1) Install & Set up mongoose */
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);
require('dotenv').config();
/** 2) Create a person */
const Schema = mongoose.Schema;
const personSchema = new Schema({
name: { type: String, required: true },
age: Number,
favoriteFoods: [String]
});
const Person = mongoose.model("Person", personSchema);
/** 3) Create and Save a Person */
const createAndSavePerson = (done) => {
let dave= new Person({name: 'Dave', age:27, favoriteFoods:['pizza','chips']})
dave.save((err,data) =>{
if(err){
console.log(err)
}else{
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/120.0.0.0 Safari/537.36
Challenge Information:
MongoDB and Mongoose - Create and Save a Record of a Model
Learn to Code — For Free
lasjorg
December 14, 2023, 7:36pm
2
The code you posted should pass. Make sure you didn’t remove the exports at the bottom of the file.
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;
How are you running it, from where, and did you use the boilerplate?
Tank you for the code I’ve already check my code and put the code you gave me but it dosen’t works it tells me this:
[Error: Cannot read properties of undefined (reading ‘modelName’)]
I’m runing it from repplit whit the green button “Run”, and sorry but i din’t understood the last part: “and did you use the boilerplate?”
lasjorg
December 15, 2023, 9:15pm
5
Post the link to your Replit.
lasjorg
December 19, 2023, 8:52pm
7
That is not the code for the same challenge. You linked to the stock checker project, not the MongoDB and Mongoose challenge.
lasjorg
December 19, 2023, 9:24pm
9
You do not have the personSchema
or Person
model you created in the previous challenge.
You should have code like this before the createAndSavePerson
function.
const PersonSchema = new Schema({
name: {
type: String,
required: true
},
age: {
type: Number
},
favoriteFoods: {
type: [String]
}
});
const Person = mongoose.model("Person", PersonSchema);
I would strongly suggest you read the article that is linked to. The challenges do (unfortunately) not provide all that much information and I’m not surprised if it is a little confusing. The curriculum is pretty terse in this section.
by Nick Karnik Introduction to Mongoose for MongoDB Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node.js. It manages relationships between data, provides schema validation, and is used to translate between objects in code and the...
I would look at YouTube and other articles on MongoDB and Mongoose as well.
system
Closed
June 19, 2024, 9:25am
10
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.