Skip to content

Instantly share code, notes, and snippets.

@Rafase282
Last active August 23, 2016 23:36
Show Gist options
  • Save Rafase282/3405fd74a2d0fa852df5e371cebcd4ec to your computer and use it in GitHub Desktop.
Save Rafase282/3405fd74a2d0fa852df5e371cebcd4ec to your computer and use it in GitHub Desktop.
MangaDB: Manga Schema
// ./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);
@Rafase282
Copy link
Author

Note that this is not the full file and is just a shortened version for education purposes, it does not work as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment