Last modified: Mon Mar 02 2020 07:15:13 GMT+0000 (Coordinated Universal Time)

Defining schema

var mongoose = require("mongoose")
var Schema = mongoose.Schema

var blogSchema = new Schema({
  title: String, // String is shorthand for {type: String}
  author: String,
  body: String,
  comments: [{ body: String, date: Date }],
  date: { type: Date, default: Date.now },
  hidden: Boolean,
  meta: {
    votes: Number,
    favs: Number
  }
})

Types

  • String
  • Boolean
  • Number
  • Date
  • Array
  • Buffer
  • Schema.Types.Mixed
  • Schema.Types.ObjectId

Difine a model

  const MODEL = mongoose.model(MODEL_NAME', MODEL_SCHEMA);

Contributors

results matching ""

    No results matching ""