Please enable JavaScript.
Coggle requires JavaScript to display documents.
MONGOOSE_2 MODEL - Coggle Diagram
MONGOOSE_2
MODEL
FLAGS
Type
Required
Lowercase/Uppercase
Converted
And-Saved
true/false
Default
value/function
() => Date.now()
Immutable
true/false
Ignores
New-Changes
Min/Max
Number-Type
min/maxLength
String-Type
Validate
Custom
Validation
Ref
ObjId-Type
NameOf
Referred
Model-Type
CREATING
Models
Folder
Model-As
models/user.js
const mongoose =
require("mongoose")
Schema
const subscriberSchema =
new mongoose.Schema({..})
name:
{ type: String
required: true }
email:
password:
TYPES
String
Date
Number
ObjIdRef
bestFriend:
{ type:
mongoose
.SchemaTypes.ObjectId
ref : "User" }
NestedObj
Way-2
const addressSchema =
new mongoose.Schema({..})
street: String,
city: String
const userSchema =
new mongoose.Schema({..})
...address: addressSchema...
Also
Creates-Id
For-AddressSchema
Way-1
addresss:
{street: String,
city: String}
CUSTOM-VALIDATION
validate: {..}
validator:
v => true/false
message:
props => "msg : " + props.value
EXPORTING
module.exports =
mongoose.model(..)
modelNameInDb
schema