lib/baseModel/lib/baseModel.js
function (callback) {
                var self = this;

                var deferred = Q.defer();
                callback = Qext.makeNodeResolver(deferred, callback);

                var breakExec = {};
                Async.waterfall([
                    function (next) {
                        if (!self.collectionName) {
                            next({
                                name: 'InternalError',
                                err: "collectionName property is not set for model " + self.identity
                            });
                        } else {
                            var dbName = self.dbName || Shared.config("environment.defaultMongoDatabase");
                            var db = self.db(dbName);
                            if (db) {
                                next(null, db);
                            }
                            else {
                                next({
                                    name: 'InternalError',
                                    err: "No connection to database " + self.identity
                                });
                            }
                        }
                    },
                    function (db, next) {

                        if (!db || _.isEmpty(db)) {
                            Logger.error("No db connection");
                            next("No db connection");
                        }
                        else {
                            //try to get exiting collection
                            db.collection(self.collectionName, {strict: true}, function (err, collection) {
                                if (!err) {
                                    //collection exists already
                                    self._collection = collection;
                                    //do not apply indexes to exiting collection, since this operation is time consuming
                                    next(breakExec, collection);
                                }
                                else {
                                    var collectionOptions = self.collectionOptions || {};
                                    db.createCollection(self.collectionName, collectionOptions, function (err, collection) {
                                        if (!err) {
                                            next(null, collection);
                                        }
                                        else {
                                            db.collection(self.collectionName, {strict: true}, function (err, collection) {
                                                if (!err) {
                                                    //collection exists already
                                                    self._collection = collection;
                                                    //do not apply indexes to exiting collection, since this operation is time consuming
                                                    next(breakExec, collection);
                                                }
                                                else {
                                                    Logger.error(err);
                                                    next(err);
                                                }
                                            });
                                        }
                                    });
                                }
                            });
                        }
                    },
                    function (collection, next) {
                        //store new collection
                        self._collection = collection;

                        if (_skipDatabaseIndexingOnNewCollections()) {
                            return next(null, collection);
                        }

                        //apply all indexes on collection
                        self.ensureAllIndexes(function (err) {
                            next(err, collection);
                        });
                    },
                    function (collection, next) {
                        //return collection
                        next(null, collection);
                    }
                ], function (err, collection) {
                    if (!err || err === breakExec) {
                        callback(null, collection);
                    }
                    else {
                        callback(err);
                    }
                });

                return deferred.promise;
            }
function (callback) {
                var self = this;

                var deferred = Q.defer();
                callback = Qext.makeNodeResolver(deferred, callback);

                var breakExec = {};
                Async.waterfall([
                    function (next) {
                        if (!self.collectionName) {
                            next({
                                name: 'InternalError',
                                err: "collectionName property is not set for model " + self.identity
                            });
                        } else {
                            var dbName = self.dbName || Shared.config("environment.defaultMongoDatabase");
                            var db = self.db(dbName);
                            if (db) {
                                next(null, db);
                            }
                            else {
                                next({
                                    name: 'InternalError',
                                    err: "No connection to database " + self.identity
                                });
                            }
                        }
                    },
                    function (db, next) {

                        if (!db || _.isEmpty(db)) {
                            Logger.error("No db connection");
                            next("No db connection");
                        }
                        else {
                            //try to get exiting collection
                            db.collection(self.collectionName, {strict: true}, function (err, collection) {
                                if (!err) {
                                    //collection exists already
                                    self._collection = collection;
                                    //do not apply indexes to exiting collection, since this operation is time consuming
                                    next(breakExec, collection);
                                }
                                else {
                                    var collectionOptions = self.collectionOptions || {};
                                    db.createCollection(self.collectionName, collectionOptions, function (err, collection) {
                                        if (!err) {
                                            next(null, collection);
                                        }
                                        else {
                                            db.collection(self.collectionName, {strict: true}, function (err, collection) {
                                                if (!err) {
                                                    //collection exists already
                                                    self._collection = collection;
                                                    //do not apply indexes to exiting collection, since this operation is time consuming
                                                    next(breakExec, collection);
                                                }
                                                else {
                                                    Logger.error(err);
                                                    next(err);
                                                }
                                            });
                                        }
                                    });
                                }
                            });
                        }
                    },
                    function (collection, next) {
                        //store new collection
                        self._collection = collection;

                        if (_skipDatabaseIndexingOnNewCollections()) {
                            return next(null, collection);
                        }

                        //apply all indexes on collection
                        self.ensureAllIndexes(function (err) {
                            next(err, collection);
                        });
                    },
                    function (collection, next) {
                        //return collection
                        next(null, collection);
                    }
                ], function (err, collection) {
                    if (!err || err === breakExec) {
                        callback(null, collection);
                    }
                    else {
                        callback(err);
                    }
                });

                return deferred.promise;
            }
function ( callback ) { var self = this ; var deferred = Q . defer ( ) ; callback = Qext . makeNodeResolver ( deferred , callback ) ; var breakExec = { } ; Async . waterfall ( [ function ( next ) { if ( ! self . collectionName ) { next ( { name : 'InternalError' , err : "collectionName property is not set for model " + self . identity } ) ; } else { var dbName = self . dbName || Shared . config ( "environment.defaultMongoDatabase" ) ; var db = self . db ( dbName ) ; if ( db ) { next ( null , db ) ; } else { next ( { name : 'InternalError' , err : "No connection to database " + self . identity } ) ; } } } , function ( db , next ) { if ( ! db || _ . isEmpty ( db ) ) { Logger . error ( "No db connection" ) ; next ( "No db connection" ) ; } else { //try to get exiting collection db . collection ( self . collectionName , { strict : true } , function ( err , collection ) { if ( ! err ) { //collection exists already self . _collection = collection ; //do not apply indexes to exiting collection, since this operation is time consuming next ( breakExec , collection ) ; } else { var collectionOptions = self . collectionOptions || { } ; db . createCollection ( self . collectionName , collectionOptions , function ( err , collection ) { if ( ! err ) { next ( null , collection ) ; } else { db . collection ( self . collectionName , { strict : true } , function ( err , collection ) { if ( ! err ) { //collection exists already self . _collection = collection ; //do not apply indexes to exiting collection, since this operation is time consuming next ( breakExec , collection ) ; } else { Logger . error ( err ) ; next ( err ) ; } } ) ; } } ) ; } } ) ; } } , function ( collection , next ) { //store new collection self . _collection = collection ; if ( _skipDatabaseIndexingOnNewCollections ( ) ) { return next ( null , collection ) ; } //apply all indexes on collection self . ensureAllIndexes ( function ( err ) { next ( err , collection ) ; } ) ; } , function ( collection , next ) { //return collection next ( null , collection ) ; } ] , function ( err , collection ) { if ( ! err || err === breakExec ) { callback ( null , collection ) ; } else { callback ( err ) ; } } ) ; return deferred . promise ; }
Gets the collection of this model. Collection is specified in the 'collectionName' property of the model.
Gets the collection of this model . Collection is specified in the collectionName property of the model .