Answers for "mongoose sample schema"

4

schema mongoose

const fruitSchema = new mongoose.Schema ({
  name: {
    type: String
  },
  rating: {
    type: Number,
    min: 1,
    max: 10
  },
  review: String
});
Posted by: Guest on July-09-2020
3

mongoose 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
    }
  });
Posted by: Guest on June-15-2020
0

mongoose sample schema

import mongoose from 'mongoose'

const { Schema } = mongoose

const value = {
  type: String,
  required: true,
  trim: true,
  unique: false
}

const UserSchema = new Schema({
  fname: value,
  lname: value,
  email: {
    type: String,
    required: true,
    trim: true,
    unique: true
  }
}, {
  timestamps: true,
  get: v => v.toDateString()
})

const User = mongoose.model('User', UserSchema)
export default User
Posted by: Guest on July-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language