{"_id":"@88bens/mongoose-multi","_rev":"2-7ce0a0ff51345790d4118aca9a0c7b03","name":"@88bens/mongoose-multi","dist-tags":{"latest":"2.0.3"},"versions":{"2.0.1":{"name":"@88bens/mongoose-multi","version":"2.0.1","description":"Create multiple Mongoose connections to severals DBs; supports also gridfs","license":"ISC","main":"index.js","maintainers":[{"name":"88bens","email":"bsmith@nerdunited.com"}],"author":{"name":"Felix Furtmayr"},"dependencies":{"mongoose":"6.4.6"},"devDependencies":{"grunt":"^1.0.1","grunt-eslint":"^20.1.0"},"scripts":{"prepublish":"npm test","test":"grunt"},"keywords":["mongoose","multi","multiple","database","mongo","gridfs","files","connection"],"repository":{"type":"git","url":"git+https://github.com/RAPIDFACTURE/mongoose-multi.git"},"bugs":{"url":"https://github.com/rapidfacture/mongoose-multi/issues"},"homepage":"https://github.com/rapidfacture/mongoose-multi#readme","gitHead":"b2cdfec493c18370d1f924dd3b525afc2067b2eb","_id":"@88bens/mongoose-multi@2.0.1","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-atjNBvUU1IkuALC+HhiFg+OwLB4amUk2feBeCqo/OX8HrIsUZKLPMiTLjDHl6i6It28H2JnTQbfR7MCRlL7Q0w==","shasum":"820e1d17623a59f9c9081aeadf17e2257fd56c6a","tarball":"https://registry.npmjs.org/@88bens/mongoose-multi/-/mongoose-multi-2.0.1.tgz","fileCount":11,"unpackedSize":25524,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCIe9EN1Dokm/BvIgYgl9IyMGM/GNUqtRz5emSqYAtCwQIhANM5DLpp3Zzd930vl1C3Xz+jTOvJFYrb8EnfXOfpG5mD"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGfgJACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmovlw//YEBHQU8hXvSg+fNvgYU4GsY45OctshfDPfqFiQqbhluDrXgC\r\nxnkcBFjFssp6uM4aIoW6dAL+JTQ9srVRrK4qd8TMl7VhCwKAn8/Xs9gnKk+4\r\nlg3u595t5ARMMlPjghV9QXuQrGDL6Lb5pky5719EsYyvX9s1ktD2o6ljL1LS\r\n+uMj5IgD06dARRHFBAh8MOJzF4D1C7RcjDnWidFSOjNZMLzP21auyVe55b34\r\nA/XLi7TolqBucV7NEmjHXXrfBq2zpD6Vog8wgi/tdDAB4iSwe0UM/KcIOmt1\r\nCSwcWSOan1N80t9QFPeJGkHZQrS3U2Z1rVtrbCqoR4gahZLXaewrKOo0jLyC\r\nNIb1oYaPWCwddxlcEpMqEy191cYNYVyQTGm2EeQGioPWJOiQ0ERoaNnHHx08\r\nI9Sqi7bu2WczIXrTFvsPDzbDSeKgYNEUhULggyF5Bt9MXsQhVJ7PWhTbSQmj\r\nXZiMxzxI2f6Bg1pSy7rJ1sVl0es4Ps0YN2oXYi/tDS/VUvkAo7OCorjvWLyx\r\nfV8pO/ZV5WjYPzqPBfPdf/2fxL1yrnzogloh22vzah3XlSRlm8L2SDi5dToK\r\nCNmzf05ErXIjgNz4q4d8HjdTrvY9tXbGkVZ9Pl37lORSrDT9txUK+QEaZaP1\r\n/uCu8BFgjnvONTMPMmX5cfaOjqE2XhupQko=\r\n=Kwhh\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"88bens","email":"bsmith@nerdunited.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-multi_2.0.1_1679423496945_0.7232575514103754"},"_hasShrinkwrap":false},"2.0.2":{"name":"@88bens/mongoose-multi","version":"2.0.2","description":"Create multiple Mongoose connections to severals DBs; supports also gridfs","license":"ISC","main":"index.js","maintainers":[{"name":"88bens","email":"bsmith@nerdunited.com"}],"author":{"name":"Felix Furtmayr"},"dependencies":{"mongoose":"6.4.6"},"devDependencies":{"grunt":"^1.0.1","grunt-eslint":"^20.1.0"},"scripts":{"prepublish":"npm test","test":"grunt"},"keywords":["mongoose","multi","multiple","database","mongo","gridfs","files","connection"],"repository":{"type":"git","url":"git+https://github.com/RAPIDFACTURE/mongoose-multi.git"},"bugs":{"url":"https://github.com/rapidfacture/mongoose-multi/issues"},"homepage":"https://github.com/rapidfacture/mongoose-multi#readme","gitHead":"06d8d34dae9d6f331e1af5e3678a52453d57dc6f","_id":"@88bens/mongoose-multi@2.0.2","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-LZbRaRncYxtx0t68MMFRU1BlgYmg2PiJlfBBPth80rBjk/u4OUgotwUBQFwTL3yl3nOgeaIL+EwIJQh7r3mWlQ==","shasum":"1c03ef21ea32e4409363ff1669a99d75d0530ee6","tarball":"https://registry.npmjs.org/@88bens/mongoose-multi/-/mongoose-multi-2.0.2.tgz","fileCount":11,"unpackedSize":25464,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE2we9O9glf+icKLlQO/yduZYB7wYs4iFru0/r7h/JtzAiAxzDZKStceS1HkEX2l0VPJcccQ0P2y0x0JyEsWCNFnMQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGg+oACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmryzg/+O/5C0yHrwHw+kcguW09G+gsQ6uO1n6KHKXYhBTo1tZEd4pmN\r\nMQ1YssEJDBWUid9TAMSOpfP/OESqcGMWi3CnZttJkvRacmKzSgujk/FcqEjq\r\nWGUhQhBIz7xeaXVTqafkSk1O2i0ai18Gs1UanOxJAtYTyITAawYqIbmXJHrC\r\nYlLPBr9jjUzRLXCyy0vPFsEuBueXRJofp9WH+XnrY03XEBW/fm8NTz5wHvkC\r\naWh6tiYcwkE6xJOR8tR5EQ0Rjda8nsnZZfRYh1l+2I48M4sfuirfttLS5njU\r\nOm0hXKHULdy7QVYdaoTXuWCxNb5narEpHaW/cjE+m2qhSkkXMUGUKKOQ2Nyy\r\nfWnYBexcm4vNvwHFg1dh1XRFbG46IfBtntPQ9Oz/1ltU9tYLGekcwZBfu/Uy\r\n43w3jv4iecvkij8sMRbKWWJSkXpYs9NTKQXHwg0gXmUxr/k0vpI6kCUT5V7X\r\nzFvhyc9+DQkwvRTI9ne+8jdlVXRxBH4WBRyy8CMfr25ZdM7QD70/V2zDp44b\r\nmA8xvq4vT5iufDkFTUeBElXyK5yKwVWewIiSFOUEn+325Vrd8qh7/6xFdp3J\r\nt/Z0zzl/cvDdfiyUpgWDPFlPnfcYhBI3UM05iRcUCGSErJGjVu5XXauNCxr3\r\nvsjfhkp5xRe2DURZdXIoj68IFqGD72KVPbg=\r\n=qu2f\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"88bens","email":"bsmith@nerdunited.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-multi_2.0.2_1679429544376_0.8900670790978138"},"_hasShrinkwrap":false},"2.0.3":{"name":"@88bens/mongoose-multi","version":"2.0.3","description":"Create multiple Mongoose connections to severals DBs; supports also gridfs","license":"ISC","main":"index.js","maintainers":[{"name":"88bens","email":"bsmith@nerdunited.com"}],"author":{"name":"Felix Furtmayr"},"dependencies":{"mongoose":"5.10.9"},"devDependencies":{"grunt":"^1.0.1","grunt-eslint":"^20.1.0"},"scripts":{"prepublish":"npm test","test":"grunt"},"keywords":["mongoose","multi","multiple","database","mongo","gridfs","files","connection"],"repository":{"type":"git","url":"git+https://github.com/RAPIDFACTURE/mongoose-multi.git"},"bugs":{"url":"https://github.com/rapidfacture/mongoose-multi/issues"},"homepage":"https://github.com/rapidfacture/mongoose-multi#readme","gitHead":"ff148486c52f5f94d268a50b238ef1131a13b56d","_id":"@88bens/mongoose-multi@2.0.3","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-7J4L2BeKpJAlg85QLFn2f+YANF3O9vPmNvggnaZEyp+oBxSc0kEi2534f7maD6RerNjNO1VZOw8pYGuuv/OMrA==","shasum":"44fadccc9a5a92e8cd74b21f675c8a971259abf8","tarball":"https://registry.npmjs.org/@88bens/mongoose-multi/-/mongoose-multi-2.0.3.tgz","fileCount":11,"unpackedSize":25465,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDGFTvn5PHwPppq5oI7pKkA0cweOcyr33tJbo5C1oUX9AIgBNVoDcHUbae9b9bIqx4zkv+T3sVV9LdQzdbQ4YKb4oE="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGilsACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr7aRAAhvudOl1cAms/mywsm5CrxTMKSVahNJf5YSJg0ji2yWFoEWG0\r\n/xMairbqkt1hbYKyE8qn//SeP7y+/9iK8rEf5Nm+nUZkQC1byU1cy+vsEUZL\r\nSLYSgEbqJxB8y6MkC+9ewXvOKuoEtGbtl5ucVPYcep5zFGmYhMWgMcbcwCXF\r\nulCtAdGmk4E44/geXdz2hd/ERIc2wfolPWxZX6CoLT6tt51zs+R7MW4bGots\r\nee2eNniqUf/pJEBCVI0nkQpWoRAswhg20y3zKPdsTQY0T9Tx8B5nzm9SbCCs\r\nLgThnvYybRY63fs0pqkcT1rmef2Rjf8gKE2ZDWjUNzp0BNYbdPm1LwWhnM5E\r\nJli3gUm9hWA1ZClYyglH/IQCF9BHfwLdgS3pTMgoToKXTZ+74eicaXAY4ebI\r\n2JRt53PHgxTjvFnEnW4BbHh619kJW7KN4Cfx51WSyhNr7qE2XJASUCYfb8lV\r\nAzOpkG8anWXqu2uKyn9HPzKrvv2Lr+5wvKoL1QEQru+KAN+oUIaMYjGDKJwh\r\nizbnxMtP2ni17Rg3eVdHfpXtfUbmdlaTPGA9MHcu/anAO6DoK1jm/zXnQPzl\r\nZfu8Nbwg2XV0PHPErUh+HI2HePqNF9KFICmlRXY4ZStDuDvBJ93U4p0Omk30\r\nEToiK5kxh6q0dbggAnnS60HddHRpfRFmBYo=\r\n=f+Nu\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"88bens","email":"bsmith@nerdunited.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-multi_2.0.3_1679436139832_0.8535653828286476"},"_hasShrinkwrap":false}},"time":{"created":"2023-03-21T18:31:36.873Z","2.0.1":"2023-03-21T18:31:37.132Z","modified":"2023-03-21T22:02:20.184Z","2.0.2":"2023-03-21T20:12:24.532Z","2.0.3":"2023-03-21T22:02:20.008Z"},"maintainers":[{"name":"88bens","email":"bsmith@nerdunited.com"}],"description":"Create multiple Mongoose connections to severals DBs; supports also gridfs","homepage":"https://github.com/rapidfacture/mongoose-multi#readme","keywords":["mongoose","multi","multiple","database","mongo","gridfs","files","connection"],"repository":{"type":"git","url":"git+https://github.com/RAPIDFACTURE/mongoose-multi.git"},"author":{"name":"Felix Furtmayr"},"bugs":{"url":"https://github.com/rapidfacture/mongoose-multi/issues"},"license":"ISC","readme":"# mongoose-multi\r\nCreate multiple Mongoose connections to severals DBs.\r\n\r\nNote: gridfs support was removed in 1.0.0\r\n\r\n## Installation\r\n\r\n```\r\nnpm install mongoose-multi --save\r\n```\r\n\r\n## Getting started\r\n\r\n### Use the module in your code\r\n\r\nThe syntax is 'database.collection' for maximum clarity.\r\n\r\n```javascript\r\ndb.application.customer.find().exec(function(err, docs) {\r\n  // do sth. here with customers\r\n});\r\n```\r\n\"customer\" is the mongoose model and can use it's methods. See <http://mongoosejs.com/docs/guide.html>.\r\n\r\n\r\n### Start the Module\r\n\r\nIdea:\r\n- network configuration in separate file (different modes for production, development, etc.)\r\n- schemas in separate file\r\n\r\n```javascript\r\n// Start the module in the application\r\nvar   dbConfig = require('./config.js').db,  // external network file\r\n      mongooseMulti = require('mongoose-multi'),\r\n      db = mongooseMulti.start(dbConfig, node.env.PWD + './schemas.js'); // schema file path => mongoose-multi trys to require it\r\n\r\n\r\n// wait for connection to be open\r\ndb.application.mongooseConnection.once('open', function () {\r\n\r\n    // use it\r\n    db.application.customer.find().exec(function(err, docs) {\r\n      // do sth. here with customers\r\n    });\r\n\r\n    db.books.article.findOneAndUpdate().exec(function(err, doc) {\r\n      // do sth. here with article\r\n    });\r\n\r\n    db.application.customer.findExactOne({}, function(err, doc) {\r\n       // err if no or more than one docs are found\r\n       // do sth. here with customer\r\n    });\r\n\r\n    db.books.article.findMinOne({}, function(err, doc) {\r\n      // err if no docs are found\r\n      // do sth. here with article\r\n    });\r\n\r\n });\r\n```\r\n\r\n#### Network config file\r\nYou might integrate this your way in your config. mongoose-multi needs one object with all database urls to connect to.\r\n\r\n```javascript\r\n module.exports = {\r\n     \"db\":{\r\n         \"application\": 'mongodb://localhost:27017/application',\r\n         \"book\": 'mongodb://localhost:27017/books'\r\n     }\r\n };\r\n```\r\n\r\n#### Mongoose Schemas file\r\n\r\n```javascript\r\n // mongose is needed here for the definition\r\n var mongoose = require('mongoose');\r\n var Schema = mongoose.Schema;\r\n\r\n\r\n module.exports = {\r\n     application:{ // database\r\n\r\n         customer: new Schema({ // collection\r\n             mailaddress: {type: String},\r\n         }),\r\n\r\n         settings: new Schema({ // collection\r\n             customerId: {type: String, required: false},\r\n             options: {type: Array, required: false},\r\n         }),\r\n\r\n     },\r\n\r\n     book:{ // database\r\n\r\n         article: new Schema({ // collection\r\n             description: {type: String},\r\n             numOfPages: {type:Number, required: false},\r\n             weight:{type:Number, required: false},\r\n         }),\r\n\r\n         paperback: new Schema({ // collection\r\n             description: {type: String, required: false},\r\n             numOfPages: {type:Number, required: false},\r\n             weight:{type:Number, required: false},\r\n         })\r\n     }\r\n\r\n };\r\n```\r\n\r\n#### Advanced Schema file options\r\n\r\nOption 1: If you need to modifie the schemas in your code, you can do so and then directly pass the object for all schemas.\r\n\r\n```javascript\r\n// Start the module\r\n var  dbConfig = require('./config.js'),  // external network file\r\n      schemaFile = require('./schemas.js'),  // external schema file\r\n      mongooseMulti = require('mongoose-multi'),\r\n      db = mongooseMulti.start(dbConfig, schemaFile);   \r\n\r\n// use \"db\" in your app  ..\r\n```\r\n\r\n\r\nOption 2: For bigger projects you can have a schema file folder. Each database has one file with it's name.\r\n\r\n```javascript\r\n// Start the module\r\n var  dbConfig = require('./config.js').db,  // external network file\r\n      mongooseMulti = require('mongoose-multi'),\r\n      db = mongooseMulti.start(dbConfig, node.env.PWD + './schemas'); // try to require all schema files within folder\r\n\r\n// use \"db\" in your app  ..\r\n```\r\n\r\n`./schemas/application` looks like:\r\n\r\n```javascript\r\n /** schemas for db application\r\n * @version 0.0.2\r\n */\r\n var mongoose = require('mongoose');\r\n var Schema = mongoose.Schema;\r\n\r\n module.exports = {\r\n    customer: new Schema({ // collection\r\n        mailaddress: {type: String},\r\n   }),\r\n\r\n   settings: new Schema({ // collection\r\n        customerId: {type: String, required: false},\r\n        options: {type: Array, required: false},\r\n   }),\r\n\r\n };\r\n```\r\n\r\n`./schemas/book` looks like:\r\n\r\n```javascript\r\n/** schemas for db book\r\n* @version 0.0.4\r\n*/\r\n var mongoose = require('mongoose');\r\n var Schema = mongoose.Schema;\r\n\r\n module.exports = {\r\n\r\n         article: new Schema({ // collection\r\n             description: {type: String},\r\n             numOfPages: {type:Number, required: false},\r\n             weight:{type:Number, required: false},\r\n         }),\r\n\r\n         paperback: new Schema({ // collection\r\n             description: {type: String, required: false},\r\n             numOfPages: {type:Number, required: false},\r\n             weight:{type:Number, required: false},\r\n         })\r\n\r\n };\r\n```\r\n\r\n\r\n#### Network config file\r\nThe network file may include all urls to your databases:\r\n\r\n```javascript\r\n module.exports = {\r\n     \"db\":{\r\n         \"application\": 'mongodb://localhost:27017/application',\r\n         \"book\": 'mongodb://localhost:27017/books'\r\n     }\r\n };\r\n```\r\n\r\nAlternative you can also pass options:\r\n\r\n```javascript\r\n module.exports = {\r\n    module.exports = {\r\n        db: {\r\n            online: {\r\n                url: \"mongodb://localhost:27017/auditoria\",\r\n                options : {useNewUrlParser: true}\r\n            },\r\n            history: {\r\n                url: \"mongodb://otheHost:27017/db_arquitectura\",\r\n                options : {}\r\n            }\r\n        }\r\n    }\r\n };\r\n```\r\n\r\n\r\n## Reuse the mongoose connection\r\n\r\nThe original mongoose connection is also returned for every DB to use it in other own modules, or especially the events like:\r\n\r\n```javascript\r\n   // we assume a database \"application\"\r\n\r\n   db.application.mongooseConnection.once('open', function() {\r\n      console('db application now open');\r\n      startSomething(db); // start after db is ready\r\n   });\r\n```\r\n\r\n\r\n\r\n## Mongoose reconnection issues\r\n\r\nThere have been several issues, that prevent a correct reconnect to the databse.\r\nIn many cases, one might never see a disconntect, but a app in production should reconnect reliable.\r\nIn this version we simple terminate the process after 10 seconds disconnect and restart it automatic with pm2.\r\nThis might be changed in the future, when there is a better and reliable workaround.\r\nCheck if this is for your process.\r\n\r\n\r\n## Development\r\nInstall the dev tools with\r\n\r\n> npm install\r\n\r\nThen you can runs some test cases and eslint with:\r\n\r\n> npm test\r\n\r\n## ToDo\r\n\r\n- tests\r\n","readmeFilename":"readme.md"}