Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongoose custom object schema

var mongoose = require('mongoose');
Schema = mongoose.Schema;

var DishSchema = new mongoose.Schema({
  dishName: { type: String },
  tags:     { type: Array },
  price:    { type: Number },
  intro:    { type: String },
  dishPic:  { type: String },
  index:    { type: Number },
  comment:  { type: [{
    date:     {type: Date, default: Date.now },
    userId:   {type: String },
    content:  {type: String }
  }]}
});

var ShopSchema = new mongoose.Schema({
  shopName:       { type: String, unique: true },
  address:        { type: String },
  location:       { type: [Number], index: '2d' },
  shopPicUrl:     { type: String },
  shopPicTrueUrl: { type: String },
  mark:           { type: String },
  open:           { type: Boolean },
  shopType:       { type: String },
  dish:           { type: [DishSchema] },
  order:          { type: [{
    orderId:  { type: String },
    date:     { type: Date, default: Date.now },
    dish:     { type: [DishSchema] },
    userId:   { type: String }
  }]}
});

var Shop = mongoose.model('Shop', ShopSchema);
module.exports = Shop;
Comment

PREVIOUS NEXT
Code Example
Javascript :: json parse string 
Javascript :: javascript count instances in string 
Javascript :: classlist js 
Javascript :: convert base64 to image nodejs 
Javascript :: inline if else javascript 
Javascript :: javascript validate date 
Javascript :: vue shortcut to create component 
Javascript :: open a particular slide on click button in owl carousel 
Javascript :: zoom out browser javascript 
Javascript :: jquery ready 
Javascript :: Import file to mongodb database 
Javascript :: javascript error discord 
Javascript :: read json from file js 
Javascript :: get document jquery 
Javascript :: yarn build react 
Javascript :: js get option value 
Javascript :: reactnative get height screen 
Javascript :: how to create jquery function 
Javascript :: send event to child component angular 
Javascript :: get params in react router dom v6 
Javascript :: start angular app server 
Javascript :: compose es6 
Javascript :: dynamic copyright year js 
Javascript :: react 404 page not found 
Javascript :: get looping in jquery 
Javascript :: how to run curl in javascript 
Javascript :: jquery await async 
Javascript :: javascript check less width of window 
Javascript :: check if is function javascript 
Javascript :: duplicates array js 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =