UNPKG

wns-mongo-package

Version:

MongoDB support package/bundle for WNS Middleware

84 lines (72 loc) 1.62 kB
/** * @WNS - The NodeJS Middleware and Framework * * @copyright: Copyright © 2012- YEPT ® * @page: http://wns.yept.net/ * @docs: http://wns.yept.net/docs/ * @license: http://wns.yept.net/license/ */ /** * No description yet. * * @author Pedro Nasser */ // Exports module.exports = { /** * Class dependencies */ extend: ['wnDbSchema'], /** * PRIVATE */ private: { _mongoSchema: {} }, /** * Public Variables */ public: {}, /** * Methods */ methods: { /** * Mongo database schema prepare; */ prepare: function () { var getSchema = function () { var colls = self.getCollections(); for (c in colls) if (_mongoSchema[c] == undefined) { for (a in colls[c]) { if (typeof colls[c][a].type=='string') { colls[c][a].type=self.getDbConnection().dataObject.base.Schema.Types[colls[c][a].type]; } if (typeof colls[c][a].schema=='object') { colls[c][a] = [ new self.getDbConnection().dataObject.base.Schema(colls[c][a].schema) ]; } } _mongoSchema[c] = new self.getDbConnection().dataObject.base.Schema(colls[c]) } } if (!this.getDbConnection().connected) this.getDbConnection().once('connect',getSchema); else getSchema(); return this; }, /** * Get mongo schema object. */ getMongoSchema: function (collection) { return (typeof collection == 'string' && _mongoSchema[collection]!=undefined) && _mongoSchema[collection]; } } };