node.jsexpressrailway.js

Where to define custom schema using RailwayJS


The docs simply say "or define custom schema (non-juggling), for example, mongoose. Please note, in case of custom schema all jugglingdb features of course will be disabled."

However..

Where exactly should this schema be created?


Solution

  • I believe you can still create it inside db/schema.js. For example:

    customSchema(function () {
    
       var mongoose = require('mongoose');
       mongoose.connect('mongodb://localhost/test');
    
       var Schema = mongoose.Schema, ObjectId = Schema.ObjectId;
    
       var BlogPost = new Schema({
            author    : ObjectId
          , title     : String
          , body      : String
          , date      : Date
       });
    
      var Post = mongoose.model('BlogPost', BlogPost);
      Post.modelName = 'BlogPost'; // this is for some features inside railway (helpers, etc)
    
      module.exports['BlogPost'] = Post;
    
    });