MongoDB and Mongoose - Create a Model

require("dotenv").config();
const mongoose = require("mongoose");

const mySecret = process.env["URI"];
const Schema = mongoose.Schema;

mongoose
  .connect(mySecret, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  })
  .then(() => console.log(" ✅ Connected to MongoDB .... Successfully"))
  .catch((err) => console.error("❌ Could not connect to MongoDB", err));

const personSchema = new Schema({
  name: { type: String, required: true },
  age: { type: Number, required: true },
  favoriteFoods: { type: String, required: true },
});
// const Person =

let Person = mongoose.model("Person", personSchema);

Why i am getting error everything run perfectly .

hello and welcome back to fcc forum :slight_smile:

  • where are you getting error?

is this from fcc curriculum, then consider share that url along with live link when possible, happy coding :slight_smile:

favoriteFoods should be of type array of strings.

  • A favoriteFoods field of type [String]

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