31 lines
616 B
JavaScript
Executable File
31 lines
616 B
JavaScript
Executable File
const mongoose = require('mongoose');
|
|
const Schema = mongoose.Schema;
|
|
|
|
mongoose.Promise = global.Promise;
|
|
mongoose.level = "F";
|
|
|
|
|
|
// Resolving error Unknown modifier: $pushAll
|
|
mongoose.plugin(schema => {
|
|
schema.options.usePushEach = true
|
|
});
|
|
|
|
const CategorySchema = new Schema({
|
|
name: {
|
|
type: String,
|
|
unique: true,
|
|
index: true,
|
|
lowercase: true
|
|
}
|
|
});
|
|
|
|
module.exports.getAllCategories = function (callback) {
|
|
Category.find(callback)
|
|
}
|
|
|
|
module.exports.getCategoryById = function (id, callback) {
|
|
Category.findById(id, callback);
|
|
}
|
|
|
|
module.exports = mongoose.model('Category', CategorySchema);
|