Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

model schema mongoose

const mongoose = require('mongoose');

const tourSchema = new mongoose.Schema({
  name: { type: String, trim: true, required: true, unique: true },
  rating: { type: Number, default: 4.5 },
  price: { type: Number, required: [true, 'A tour must have price'] },
  duration: { type: Number, required: [true, 'A tour must have a duration'] },
  maxGroupSize: {
    type: Number,
    required: [true, 'A tour must have a group size'],
  },
  difficulty: { type: String, required: [true, 'A tour must have difficulty'] },
  ratingAverage: { type: Number, default: 4.5 },
  ratingQuantity: { type: Number, default: 0 },
  priceDiscount: Number,
  summary: {
    type: String,
    trim: true,
    required: [true, 'A tour must have a description'],
  },
  description: { type: String, trim: true },
  imageCover: {
    type: String,
    required: [true, 'A tour must have a cover image'],
  },
  image: [String],
  createdAt: { type: Date, dafault: Date.now(), select: false },
  startDates: [Date],
});

const Tour = mongoose.model('Tour', tourSchema);
module.exports = Tour;
Comment

mongoose schema/Creating a model

const Blog = mongoose.model('Blog', blogSchema);
  // ready to go!
Comment

Mongoose Model Schema

let movieSchema = mongoose.Schema({
  Title: {type: String, required: true},
  Description: {type: String, required: true},
  Genre: {
    Name: String,
    Description: String
  },
  Director: {
    Name: String,
    Bio: String
  },
  Actors: [String],
  ImagePath: String,
  Featured: Boolean
});

let userSchema = mongoose.Schema({
  Username: {type: String, required: true},
  Password: {type: String, required: true},
  Email: {type: String, required: true},
  Birthday: Date,
  FavoriteMovies: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Movie' }]
});

let Movie = mongoose.model('Movie', movieSchema);
let User = mongoose.model('User', userSchema);

module.exports.Movie = Movie;
module.exports.User = User;
Comment

PREVIOUS NEXT
Code Example
Javascript :: force update react hooks 
Javascript :: sort array with objects 
Javascript :: how to find unique elements in array in javascript 
Javascript :: JavaScript changing the color of an html element 
Javascript :: react router 404 redirect 
Javascript :: hide gridlines in chart js 
Javascript :: create link and click javascript 
Javascript :: how to convert time to am pm in javascript 
Javascript :: inline style boarder radius jsx 
Javascript :: javascript clear form after dubmit 
Javascript :: implementating step component in react 
Javascript :: javascript function description standards 
Javascript :: scroll to bottom of a div 
Javascript :: dummy json 
Javascript :: stop a setinterval 
Javascript :: jquery get label from select 
Javascript :: add and remove checked jquery 
Javascript :: p5.js style 
Javascript :: js distance from top 
Javascript :: react native image disable fade in onload 
Javascript :: check if character is a letter 
Javascript :: check if element is last child jquery 
Javascript :: react-native-checkbox in a loop 
Javascript :: how to check if an element is in an array javascript 
Javascript :: loop through json object javascript 
Javascript :: select option value jquery 
Javascript :: vanilla tilt.js 
Javascript :: javascript add quote comma 
Javascript :: aos animation react npm 
Javascript :: jquery text replace 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =