Mongoose Model

noun

say it: “MOON-goos MOD-ul” /ˈmunˌɡus ˈmɑdəl/

In Mongoose, the object made from a schema that saves, finds, updates and deletes one kind of document.

What is a Mongoose model?

A Mongoose model is made from a schema with mongoose.model, and it's what your code calls to save and find that kind of document in its collection, with methods such as create, find and findById.

const Workout = mongoose.model("Workout", workoutSchema);

await Workout.create({ type: "run", minutes: 30 });
const runs = await Workout.find({ type: "run" });
console.log(runs.length); // 1

In a sentence

  • “The routes call the Workout Mongoose model instead of touching the collection directly.”
  • “A Mongoose model named Workout keeps its documents in the workouts collection.”

Level: Journeyman · More MongoDB terms at this level

Updated