Sunday, 25 January 2015

keystonejs how to set your model to map to another table(collection) instead of default plural rule

If you use Keystonejs to manage your table in mongodb, you can create a model like this:



PostCategory.add({
name: { type: String, required: true }
});



However, Keystonejs will create you a table --- postcategories:



That because Keystonejs uses mongoose which can automatically create the plural form of your model.

To make your model to map to anther table(collection) you can:


var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var DesignSchema = new Schema({
name: String
},
{collection: 'YOUCOLLECTIONNAME'});
module.exports = mongoose.model('Design', DesignSchema);


















No comments:

Post a comment