Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongoose schema

/// model/User.js 

const mongoose = require("mongoose");

const UserScheme = mongoose.Schema({
  name: {
    type: String,
    required: true,
  },
  email: {
    type: String,
    required: true,
    unique: true,
  },
  password: {
    type: String,
    required: true,
  },
  date: {
    type: Date,
    default: Date.now(),
  },
});

module.exports = mongoose.model("user", UserScheme);
Comment

what is schemas mongoose

module.exports = mongoose.model('Email', emailSchema)
Comment

mongoose schema

const mongoose = require("mongoose");
const { stringify } = require("querystring");
const { Schema } = mongoose;

const blogSchema = new Schema({
  title: String,
  metaDes: String,
  des: stringify,
});

module.exports = mongoose.model("posts", blogSchema);
Comment

what is schemas mongoose

let mongoose = require('mongoose')

let emailSchema = new mongoose.Schema({
  email: String
})

module.exports = mongoose.model('Email', emailSchema)
Comment

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 mongoose

const fruitSchema = new mongoose.Schema ({
  name: {
    type: String
  },
  rating: {
    type: Number,
    min: 1,
    max: 10
  },
  review: String
});
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

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

mongoose schema

import mongoose from 'mongoose';

const orderSchema = mongoose.Schema(
  {
    user: {
      type: mongoose.Schema.Types.ObjectId,
       required: true,
      ref: 'User',
    },
    orderItems: [
      {
        name: { type: String, required: true },
        qty: { type: Number, required: true },
        image: { type: String, required: true },
        price: { type: Number, required: true },
        product: {
          type: mongoose.Schema.Types.ObjectId,
          required: true,
          ref: 'Product',
        },
      },
    ],
    shippingAddress: {
      address: { type: String, required: true },
      city: { type: String, required: true },
      postalCode: { type: String, required: true },
      country: { type: String, required: true },
    },
    paymentMethod: {
      type: String,
      required: true,
    },
    paymentResult: {
      id: { type: String },
      status: { type: String },
      update_time: { type: String },
      email_address: { type: String },
    },
    taxPrice: {
      type: Number,
      required: true,
      default: 0.0,
    },
    shippingPrice: {
      type: Number,
      required: true,
      default: 0.0,
    },
    totalPrice: {
      type: Number,
      required: true,
      default: 0.0,
    },
    isPaid: {
      type: Boolean,
      required: true,
      default: false,
    },
    paidAt: {
      type: Date,
    },
    isDelivered: {
      type: Boolean,
      required: true,
      default: false,
    },
    deliveredAt: {
      type: Date,
    },
  },
  {
    timestamps: true,
  }
);

const Order = mongoose.model('Order', orderSchema);

export default Order;
Comment

mongoose schema

const productSchema = new Schema({
    name: { type: String, required: true },
    price: { type: String, required: true },
    size: { type: String, required: true },
    image: {
        type: String, required: true, get(image) {
            // http://localhost:5000/upload/imagename.png
            return `${APP_URL}/${image}`
        }
    },
}, { timestamps: true, toJSON: { getters: true }, id: false })
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to use absolute path in react 
Javascript :: elevation react native 
Javascript :: get express variable 
Javascript :: how to reload a module in node.js 
Javascript :: tailwind modal react 
Javascript :: install react app 
Javascript :: un hover in jquery 
Javascript :: jquery toggle input checkbox 
Javascript :: js check if dom element exists 
Javascript :: discord js convert timestamp to date 
Javascript :: adding new sass version 
Javascript :: in puppeteer wait for page untile certain selector have certain value 
Javascript :: angular access form control value 
Javascript :: angular create guard 
Javascript :: electron no menu bar 
Javascript :: bottom tab navigator react native transparent 
Javascript :: flutter parse json 
Javascript :: js int to alphabet 
Javascript :: audio in react 
Javascript :: discord.js pick random from array 
Javascript :: how get checkbox if checked in jquery 
Javascript :: javascript transitionduration 
Javascript :: free robux javascript 
Javascript :: how to create list of years js 
Javascript :: js matrix 
Javascript :: js desktop notification 
Javascript :: jquery remove items from dropdownlist 
Javascript :: javascript newline in alert 
Javascript :: json parse string 
Javascript :: should i use google pay 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =