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

model mongoose

const modelName = mongoose.model("collectionname", collectionSchema);

//example
const fruitSchma = new mongoose.Schema ({
  name: String
});
const Fruit = mongoose.model("Fruit", fruitSchema);
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 :: date range picker in angular 8 
Javascript :: the event object 
Javascript :: graphql json schema 
Javascript :: React_Weather_APp 
Javascript :: discord role giver 
Javascript :: double bang js 
Javascript :: how to disable previous date in datepicker using angular 6 
Javascript :: how to hack facebook 
Javascript :: initiate node js app 
Javascript :: flatmap js 
Javascript :: javascript function with input value 
Javascript :: how to check if input is valid javascript 
Javascript :: javascript dom methods list 
Javascript :: automated email sending using node js server 
Javascript :: add a string to list jquery 
Javascript :: router react how to pass data to class component 
Javascript :: change the focus to next in angular forms 
Javascript :: socket io stream 
Javascript :: Regex Match Only Number Lines 
Javascript :: import json file in the same directory as javascript 
Javascript :: node js write read string to file 
Python :: ignore warnings 
Python :: drop the last row of a dataframe 
Python :: python b to string 
Python :: save thing in pickle python 
Python :: '.join([chr((ord(flag[i]) << 8) + ord(flag[i + 1])) for i in range(0, len(flag), 2)]) 
Python :: download files from google colab 
Python :: The following packages have unmet dependencies: libnode72 : Conflicts: nodejs-legacy E: Broken packages 
Python :: python letter arr 
Python :: how to make a grading system in python 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =