Sunday, 25 January 2015

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

If you create an API in fullstack, you will have a code like this:

'use strict';

var mongoose = require('mongoose'),
    Schema = mongoose.Schema;

var PostSchema = new Schema({
  name: String,
  info: String,
  active: Boolean
});

module.exports = mongoose.model('Post', PostSchema);

It will create a table -- posts in your mongodb.

Good?

If you want this model map to another table, for example -- post, you can do like this:


var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var TestobjSchema = new Schema({
title: String,
description: String
},
{collection: 'YOUTABLENAME'});
module.exports = mongoose.model('TestObj', TestobjSchema);



























No comments:

Post a comment