tweeio / twee-framework

Modern MVC Framework for Node.js and io.js based on Express.js for professionals with deadlines in enterprise
http://twee.io
114 stars 11 forks source link

Added Mongoose Extension, seeing 3 mongoose connections in log #3

Closed waygee closed 9 years ago

waygee commented 9 years ago

Following the directions at: https://github.com/tweeio/twee-mongoose-extension, I made the following changes in my application/configs/twee.js

module.exports = {
    "extensions": {
        "Session": {
            "module": "twee-session-extension"
        },
        "Mongoose": {
            "module": "twee-mongoose-extension"
        }
    },
    "options": {
        "errorPages": {
            "404": {
                "viewTemplate": __dirname + "/../views/common/pages/404.html"
            }
        }
    },
    "extension": {
        "twee-mongoose": {
            "databases": {
                "myBusiness": {
                    "connection": "mongodb://localhost/myBusiness"
                },
                "anotherBusiness": {
                    "connection": "mongodb://localhost/anotherBusiness,mongodb://anotherHost.com/anotherBusiness",
                    "options": {
                        // Multi-mongos support
                        "mongos": true
                    }
                },
            },
            "defaultDatabase": "myBusiness"
        }
    }
 }

When I start up the application, I get the following:

$npm start

> application@0.0.1 start /home/safeuser/application
> NODE_PATH=./node_modules NODE_ENV=development DEBUG=twee.io node ./application.js

  twee.io [WORKER:6233] NODE_ENV: development +0ms
  twee.io [WORKER:6233] [MODULE] Loading: Default +6ms
  twee.io [WORKER:6233] [MODULE::Default][CONFIGS::common] Loaded: /home/safeuser/application/modules/Default/setup/configs/common.js +2ms
  twee.io [WORKER:6233] [MODULE::Default][CONFIGS::grunt] Loaded: /home/safeuser/application/modules/Default/setup/configs/grunt.js +1ms
  twee.io [WORKER:6233] [MODULE::Default][CONFIGS::common] Loaded: /home/safeuser/application/modules/Default/setup/configs/development/common.js +1ms
  twee.io [WORKER:6233] [MODULE] Loading: Blog +1ms
  twee.io [WORKER:6233] [MODULE::Blog][CONFIGS::common] Loaded: /home/safeuser/application/modules/Blog/setup/configs/common.js +1ms
  twee.io [WORKER:6233] [MODULE::Blog][CONFIGS::grunt] Loaded: /home/safeuser/application/modules/Blog/setup/configs/grunt.js +1ms
  twee.io [WORKER:6233] [MODULE::Blog][CONFIGS::common] Loaded: /home/safeuser/application/modules/Blog/setup/configs/development/common.js +1ms
  twee.io [WORKER:6233] [EXTENSION::HTTP Parser] Installed (configNamespace: twee-http-parser) +47ms
  twee.io [WORKER:6233] [EXTENSION::Winston Logger] Installed (configNamespace: twee-logging) +97ms
  twee.io [WORKER:6233] [EXTENSION::`Powered With` Header] Installed (configNamespace: twee-powered) +2ms
  twee.io [WORKER:6233] [EXTENSION::Static Files] Installed (configNamespace: twee-static) +133ms
  twee.io [WORKER:6233] [EXTENSION::HTML Compressor] Installed (configNamespace: twee-compressor) +36ms
  twee.io [WORKER:6233] [EXTENSION::View Engines] Installed (configNamespace: twee-view) +4ms
  twee.io [WORKER:6233] [EXTENSION::View Helpers] Installed (configNamespace: undefined) +33ms
  twee.io [WORKER:6233] [EXTENSION::i18n] Installed (configNamespace: twee-i18n) +12ms
  twee.io [WORKER:6233] [EXTENSION::Mongoose] Installed (configNamespace: twee-mongoose) +262ms
  twee.io [WORKER:6233] [MODULE::Default][EXTENSION::Default Extensions] Installed (configNamespace: undefined) +2ms
  twee.io [WORKER:6233] [MODULE::Blog][EXTENSION::Blog Extensions] Installed (configNamespace: undefined) +2ms
  twee.io [WORKER:6233] Worker 6233 spawned +5ms
  twee.io [WORKER:6233] [MODULE::Default][MIDDLEWARE::Default Middleware] Installed +1ms
  twee.io [WORKER:6233] [MODULE::Default][MIDDLEWARE::SwitchLanguage] Installed +1ms
  twee.io [WORKER:6233] [MODULE::Blog][MIDDLEWARE::Blog Middleware] Installed +1ms
  twee.io [WORKER:6233] [MODULE::Blog][MIDDLEWARE::SwitchLanguage] Installed +0ms
  twee.io [WORKER:6233] [MODULE::Default][CONTROLLER::DefaultController] Loading +2ms
  twee.io [WORKER:6233] [MODULE::Default][ROUTE] HTTP METHOD: all. ACTION: DefaultController.indexAction +1ms
  twee.io [WORKER:6233] [MODULE::Default][ROUTE] HTTP METHOD: all. ACTION: DefaultController.bootstrapAction +0ms
  twee.io [WORKER:6233] [MODULE::Default][ROUTE] HTTP METHOD: all. ACTION: DefaultController.testAction +1ms
  twee.io [WORKER:6233] [MODULE::Blog][CONTROLLER::BlogController] Loading +0ms
  twee.io [WORKER:6233] [MODULE::Blog][ROUTE] HTTP METHOD: all. ACTION: BlogController.indexAction +2ms
  twee.io [WORKER:6233] [MODULE::Blog][ROUTE] HTTP METHOD: all. ACTION: BlogController.bootstrapAction +0ms
  twee.io [WORKER:6233] Opened Mongoose DB connection: "anotherBusiness" (mongodb://localhost/anotherBusiness,mongodb://anotherHost.com/anotherBusiness) +20ms
  twee.io [WORKER:6233] Opened Mongoose DB connection: "anotherBusiness" (mongodb://localhost/anotherBusiness,mongodb://anotherHost.com/anotherBusiness) +1ms
  twee.io [WORKER:6233] Opened Mongoose DB connection: "anotherBusiness" (mongodb://localhost/anotherBusiness,mongodb://anotherHost.com/anotherBusiness) +2s

Note, the last 3 entries, why are there 3 connections for anotherBusiness? Also, why is there no connection for myBusiness?

waygee commented 9 years ago

I simplified twee.js to the following, and still getting what seems to be two connections in the log:

module.exports = {
    "extensions": {
        "Session": {
            "module": "twee-session-extension"
        },
        "Mongoose": {
            "module": "twee-mongoose-extension"
        }
    },
    "options": {
        "errorPages": {
            "404": {
                "viewTemplate": __dirname + "/../views/common/pages/404.html"
            }
        }
    },
    "extension": {
        "twee-mongoose": {
            "databases": {
                "myBusiness": {
                    "connection": "mongodb://localhost/myBusiness"
                }
            }
        }
    }
 }
mesin commented 9 years ago

Looking into this! Will push fix very soon

mesin commented 9 years ago

Yes I know why. Because during adding new databases in your application config you added two more connections to this one which is default: https://github.com/tweeio/twee-mongoose-extension/blob/master/index.js#L212

Do you think I should remove default connection from there? But definitely i'll remove connection details because don't know how to not rewrite dbName in open and error callbacks.. Do you know?

waygee commented 9 years ago

I was trying to figure out how to change the default mongo connection and override it. Is there a way to do this? If there is a way to override the default connection, could you clarify?

mesin commented 9 years ago

Just to overwrite default connection you can write this:

"test": { "connection": "your connection string", "options": {} }

Probably it could be better to use default instead of test, do you think?

waygee commented 9 years ago

Sorry for not understanding, what file would I write this in? Also, I thing default is definitely better.

mesin commented 9 years ago

You should write it in the same place where you did your changes.

module.exports = {
    "extensions": {
        "Session": {
            "module": "twee-session-extension"
        },
        "Mongoose": {
            "module": "twee-mongoose-extension"
        }
    },
    "options": {
        "errorPages": {
            "404": {
                "viewTemplate": __dirname + "/../views/common/pages/404.html"
            }
        }
    },
    "extension": {
        "twee-mongoose": {
            "databases": {
                "test": {
                    "connection": "mongodb://localhost/myBusiness"
                }
            }
        }
    }
 }

Ok I'll fix it to be default right now.

waygee commented 9 years ago

ok, thanks for your help and quick answers.

mesin commented 9 years ago

Here is it new fix: https://github.com/tweeio/twee-mongoose-extension/blob/master/index.js#L212

Now you can replace test with default Just remove twee-mongoose-extension in node_modules and do npm install once more.

waygee commented 9 years ago

Yes, that worked fine!

mesin commented 9 years ago

Thank you for giving it try I'm working hard every day to make it better Soon I'll post few improvements and sequelize and bookshelf integration Also more videos and examples will be :-)