Mongoose schema

Need a regular mongoose schema ?

Inside the model file, pass also a mongoose schema

src\models\posts.model.js
// posts-model.js - A mongoose model
// 
// See http://mongoosejs.com/docs/models.html
// for more of what you can do here.

const postsValidators = require('../validators/posts.validators.js');
const {createModelFromJoi} = require('feathers-mongoose-casl');
var mongoose = require('mongoose');

const mongooseSchema = var sampleSchema = new mongoose.Schema({ name: { type: String, required: true } });
module.exports = function (app) {
  return createModelFromJoi(app, 'posts', postsValidators, mongooseSchema);
};

Why we use JOI

  1. You need to create a validator file for each mongoose service in your app

  2. The file need to export a function that will return a JOI schema

  3. With joigoose we will convert this schema to mongoose schema

  4. With joi2jso we will convert this scheme to JSON schema for the dashboard

Last updated