How to Create and Save Schema Array of Strings in Mongoose?

Schema Arrays in Mongoose are supported like any other schema, except that each key is used as an array of values. Using Schema Arrays is especially useful when constructing a GraphQL query, as it enables you to work with items that have more than one attribute. Mongoose is a Node.js module designed to expose a familiar Model-relation MVC pattern to Mongo databases. 

mongoose custom object schema

on Jan 01, 1970
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;

Add Comment

0

It also provides an elegant solution for client-side validation, intentionally making it easier to follow the same server-side rules when creating mongoose models.

Javascript answers related to "mongoose object type schema"

View All Javascript queries

Javascript queries related to "mongoose object type schema"

mongoose object type schema mongoose schema type double mongoose referenced schema JSON schema enumerated type mongoose delete object from array Cannot assign to read only property 'value' of object '[object Object] get table schema with knex paging react mongoose node mongoose save document mongoose find by and delete mongoose connect to URL of atals mongoose bulk update mongoose find by nested property how to get data from multiple tables mongoose how pop in mongoose mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true, useCreateIndex: true, }); timestamps in mongoose comparing mongoose ids and strings mongoose nestjs finding in mongoose using a name npm passport-local-mongoose how to use mongoose populate how to use mongoose aggregate countDocuments mongoose flutter access json object inside object property 'name' does not exist on type 'eventtarget' react ReactElement Function lacks ending return statement and return type does not include 'undefined'. node js type error node js TypeError [ERR_INVALID_ARG_TYPE]: The argument must be of type string. Received undefined node package.json type module remove mime type from base64 javascript Property 'value' does not exist on type 'EventTarget & Element'. REACT TS roperty 'value' does not exist on type 'EventTarget & Element' ajax content type multipart/form-data jquery each array object jquery scroll when object appear on screen make animation how to get property names from object using map method react reactjs get url query params as object Updating an object with setState in React print map object nodejs res object anatomy nodejs how to remove duplicate array object in javascript how to check if object is empty javascript javascript object to json javascript object entries javascript object destructuring foreach object javascript javascript convert array to object javascript object to array how to convert an array into an object using javascript converting object to array in js js push in object make an object javascript where is select value in javascript event object javascript add parameter to object add object in array javascript to index using lodash Return Distinct Array Object three js get size of object sort object by value javascript javascript array vs object updating json object in mysql database js does object exist in array js object some indexof object javascript js object destructuring with defaults javascript object get subset clone an object javascript add an object to index 0 array js javascript check if json object is valid path object d3.js javascript object instead of switch object destructuring default value json object array javascript set object key as variable updating a key value on javascript object es6 find object in array mongodb how to make arrow functions as object methods flatten nested object forming an object with reduce map object object how did you implement page object model urlsearchparams to object why do we use Object Constructors typescript check if object has key max value array of object javascript javascripts object filter duplicate value in array of object typescript how to remove elements from object in typescript trim undefined keys from object typescript how to use variable as object key in typescript react replace object in array add data to json object Convert json string to json object javascript jquery find object in array javascript object get value by key Javascript converting object to array javascript foreach object js object foreach

Browse Other Code Languages

CodeProZone