Source: mongodb/models/geo.js

/**
 * @module mongodb/models/geo
 */

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var util = require('util');
var _ = require('underscore');
var mongooseApiQuery = require('mongoose-api-query');

// ---- Geo Collections Models ---- //

/**
 * Geo schema shared by Country, Region models.
 * @class
 * @type {Schema}
 */
var geoSchema = new Schema({
    _id: { type: String, required: true}, // same as code
    name: { type: String, required: true},
    code: { type: String, required: true}
});
geoSchema.plugin(mongooseApiQuery);
var Country = mongoose.model('Country', geoSchema);
var Region = mongoose.model('Region', geoSchema);

/**
 * DMA Schema -- similar to Geo schema but with numbers as
 * `_id` and `code`
 */
var dmaSchema = new Schema({
    _id: { type: Number, required: true}, // same as code
    name: { type: String, required: true},
    code: { type: Number, required: true}
});
dmaSchema.plugin(mongooseApiQuery);
var DMA = mongoose.model('DMA', dmaSchema);

/**
 * Models wrapper to be instantiated w/ specific DB connection instance.
 *
 * @param {mongoose.connection} connection DB connection object
 * @constructor
 */
var GeoModels = function(connection){
    this.connection = connection;
    this.Country = this.connection.model('Country');
    this.Region = this.connection.model('Region');
    this.DMA = this.connection.model('DMA');
};
exports.GeoModels = GeoModels;