MongoDB connectivity layer
Using the Common MongoDB Connection
Initializing the connection
This must be done once by the main server process. This is done by the Norman AppServer, you may do this manually in your service tests.
Optional second parameter allows configuring the deployment strategy. Default strategy "single" stores all Norman collection into a single database. Production strategy "distribute" spreads the collections over multiple domain databases to reduce write contention. Database distribution may be fine-tuned with the "map" strategy.
Getting a mongoose connection
The following code snippet returns a connection to the database configured for the module "my-module" according to the deployment strategy.
var connection = commonserverdbconnection;
Getting a Mongo database connection
var db1 = commonserverdbconnection;var db2 = commonserverdbconnectiondb;
Creating mongoose models
We offer a simple way to define mongoose model on a specific connection :
var commonServer =mongoose = commonServerdbmongoose;var MySchema = mongoose;moduleexports = mongoose;