MongoDB and Mongoose - Create a Model

hi guys please i need your helps this is the code below //

var Schema = mongoose.Schema;

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

});

var someone = model('Person', schema);

const createAndSavePerson = (done) => {
  const person = new Person({
    name: "Sona",
    age: 12,
    favoriteFoods: ["Chicken Noodles", "Fruits"]
  });

  someone.save(function(err, data) {
    return console.log(err)
    done(null, data);
  });

the code is not woking
link is boilerplate-mongomongoose - Replit

You are missing the closing bracket } for the createAndSavePerson function.

i do it is not always working

Your Schema types are wrong.

https://mongoosejs.com/docs/schematypes.html

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