Last active
August 23, 2016 23:36
-
-
Save Rafase282/3405fd74a2d0fa852df5e371cebcd4ec to your computer and use it in GitHub Desktop.
MangaDB: Manga Schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./models/manga.js | |
// Load required packages | |
var mongoose = require('mongoose'); | |
// Define our user schema | |
var MangaSchema = new mongoose.Schema({ | |
title: { | |
type: String, //It has to be a string | |
lowercase: true, // make it lowercase | |
trim: true, // removes trailing white spaces | |
required: true, //cannot be empty | |
unique: true, //no similar data on the db | |
match: /[a-z]/ // uses regex to ensures there are no numbers (2 !=="2") | |
}, | |
categories: [{ // makes it an array | |
... | |
}], | |
chapter: { | |
type: Number, //makes it to be a number | |
min: 0, //ensures the minimum number is zero | |
match: /[0-9]/ //regex to enforce numbers, probably not needed due to type. | |
}, | |
userId: { | |
... | |
match: /[a-z-0-9]+/ //basically makes it alphanumeric | |
} | |
}).set('toObject', { | |
retainKeyOrder: true | |
}); | |
// Export the Mongoose model | |
module.exports = mongoose.model('Manga', MangaSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this is not the full file and is just a shortened version for education purposes, it does not work as it is.