본문 바로가기

코딩

Schema Types, String, Number, Date, ObjectId

728x90

All Schema Types

  • required: boolean or function, if true adds a required validator for this property
  • default: Any or function, sets a default value for the path. If the value is a function, the return value of the function is used as the default.
  • select: boolean, specifies default projections for queries
  • validate: function, adds a validator function for this property
  • get: function, defines a custom getter for this property using Object.defineProperty().
  • set: function, defines a custom setter for this property using Object.defineProperty().
  • alias: string, mongoose >= 4.10.0 only. Defines a virtual with the given name that gets/sets this path.
  • immutable: boolean, defines path as immutable. Mongoose prevents you from changing immutable paths unless the parent document has isNew: true.
  • transform: function, Mongoose calls this function when you call Document#toJSON() function, including when you JSON.stringify() a document.

String

  • lowercase: boolean, whether to always call .toLowerCase() on the value
  • uppercase: boolean, whether to always call .toUpperCase() on the value
  • trim: boolean, whether to always call .trim() on the value
  • match: RegExp, creates a validator that checks if the value matches the given regular expression
  • enum: Array, creates a validator that checks if the value is in the given array.
  • minLength: Number, creates a validator that checks if the value length is not less than the given number
  • maxLength: Number, creates a validator that checks if the value length is not greater than the given number
  • populate: Object, sets default populate options

Number

  • min: Number, creates a validator that checks if the value is greater than or equal to the given minimum.
  • max: Number, creates a validator that checks if the value is less than or equal to the given maximum.
  • enum: Array, creates a validator that checks if the value is strictly equal to one of the values in the given array.
  • populate: Object, sets default populate options

Date

  • min: Date
  • max: Date

ObjectId

 

Mongoose v6.0.14: Query Population

MongoDB has the join-like $lookup aggregation operator in versions >= 3.2. Mongoose has a more powerful alternative called populate(), which lets you reference documents in other collections. Population is the process of automatically replacing the specifi

mongoosejs.com

 

예)

const videoSchema = mongoose.Schema({
    title: { type: String, required: true, uppercase: true, trim: true, maxLength: 80 },
    description: { type: String, required: true, trim: true, minLength: 20 },

'코딩' 카테고리의 다른 글

Model  (0) 2021.12.01
Schema quries  (0) 2021.12.01
github Desktop 이용법 /static website hosting  (0) 2021.10.13
SPA(Single Page Application)  (0) 2021.10.06
GitHub와 Git  (0) 2021.10.06