Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Defining Schema mongoose

import mongoose from 'mongoose';
  const { Schema } = mongoose;

  const blogSchema = new Schema({
    title:  String, // String is shorthand for {type: String}
    author: String,
    body:   String,
    comments: [{ body: String, date: Date }],
Javascript
1
import mongoose from 'mongoose';
2
  const { Schema } = mongoose;
3
​
    date: { type: Date, default: Date.now },
    hidden: Boolean,
    meta: {
      votes: Number,
      favs:  Number
    }
  });
Comment

schema in mongoose

//1st style
 var mongoose = require('mongoose');
  var Schemax = mongoose.Schema;

  var blogSchema = new Schemax({
    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
    }
  });
  module.exports =  mongoose.model( 'model name' , blogSchema);
  
 

//2nd style
 const mongoose = require('mongoose')    
const Schema Name = mongoose.Schema({
    name : {
        type : String,
        default : 'default txt',
    },
})
module.exports =  mongoose.model( 'model name' , Schema Name);
Comment

mongoose schema example

import mongoose from 'mongoose';
const { Schema } = mongoose;

const 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
  }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript brightness filter 
Javascript :: javascript case insensitive regex 
Javascript :: map method 
Javascript :: inertia.js 
Javascript :: how to add google map in react js 
Javascript :: js toggle multiple classes 
Javascript :: node js mongodb update nested object 
Javascript :: Remove escape characters from JSON Data 
Javascript :: how to add dropdown with filter in angular material 
Javascript :: date pipe 
Javascript :: type js 
Javascript :: what is react easy emoji 
Javascript :: javascript map with arrow function 
Javascript :: mongoose id validator 
Javascript :: gitea 
Javascript :: object.assign in express 
Javascript :: open modal using jquery 
Javascript :: array example 
Javascript :: where from terminal colors come 
Javascript :: material ui table row height 
Javascript :: js get smallest value of array 
Javascript :: react-native-geolocation-service 
Javascript :: add role command discord.js 
Javascript :: use node js as backend with angular frontend 
Javascript :: add a slash to string in javascript 
Javascript :: discord.js embed 
Javascript :: JavaScript Change the Elements of an Array 
Javascript :: node js package nodemon error 
Javascript :: socket io stream 
Javascript :: npm html-validate 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =