{"id":21867332,"url":"https://github.com/ktbsomen/mongoplusplus","last_synced_at":"2026-05-05T13:36:04.839Z","repository":{"id":225146433,"uuid":"765194558","full_name":"KTBsomen/mongoplusplus","owner":"KTBsomen","description":"mongoplusplus is a Node.js package designed to facilitate load balancing of read and write operations across multiple MongoDB databases. It simplifies database connection management, schema definition, model building, and CRUD operations execution.","archived":false,"fork":false,"pushed_at":"2026-04-12T15:52:46.000Z","size":43,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-28T01:16:43.525Z","etag":null,"topics":["load-balancer","mongodb-atlas","mongoose","mongoplusplus","multiple-database-connection","multiple-databases","nodejs","nodejs-modules","nodejsmongodbapi","orm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KTBsomen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-02-29T13:10:09.000Z","updated_at":"2026-04-12T15:52:50.000Z","dependencies_parsed_at":"2025-03-21T21:37:33.152Z","dependency_job_id":null,"html_url":"https://github.com/KTBsomen/mongoplusplus","commit_stats":null,"previous_names":["ktbsomen/mongoplusplus"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KTBsomen/mongoplusplus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTBsomen%2Fmongoplusplus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTBsomen%2Fmongoplusplus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTBsomen%2Fmongoplusplus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTBsomen%2Fmongoplusplus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KTBsomen","download_url":"https://codeload.github.com/KTBsomen/mongoplusplus/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTBsomen%2Fmongoplusplus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32651669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-05T11:29:49.557Z","status":"ssl_error","status_checked_at":"2026-05-05T11:29:48.587Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["load-balancer","mongodb-atlas","mongoose","mongoplusplus","multiple-database-connection","multiple-databases","nodejs","nodejs-modules","nodejsmongodbapi","orm"],"created_at":"2024-11-28T05:09:13.915Z","updated_at":"2026-05-05T13:36:04.832Z","avatar_url":"https://github.com/KTBsomen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoplusplus\n\n## Overview\n\n`mongoplusplus` is a Node.js package designed to facilitate load balancing of read and write operations across multiple MongoDB databases. It simplifies database connection management, schema definition, model building, and CRUD operations execution.\n\n## Installation\n\nInstall mongoplusplus via npm:\n\n```bash\nnpm install mongoplusplus\n```\n\nimporting\n```node\nconst mongoplusplus = require('mongoplusplus');\n```\n##Initialing\n```node\nconst dbname = 'testforUP';\n\nconst mongoURI1 = `mongodb+srv://xxxxx:xxxxxx@cluster0.xxxxx.mongodb.net/${dbname}?retryWrites=true\u0026w=majority`;\nconst mongoURI2 = `readonly:mongodb+srv://xxxxxxx:xxxxxx@cluster0.xxxxxx.mongodb.net/${dbname}?retryWrites=true\u0026w=majority`;\nconst mongodb = new mongoplusplus([mongoURI1, mongoURI2]);\n\n```\n##connecting database\nthis is the top level thing in your main page (in this test code, under mongodb variable declaration  )\n```node\n(async () =\u003e {\n  await mongodb.connectToAll();\n})();\n```\n##Schema defining \nit is very  similar to Mongoose schema definition.but only one mandatory field must be there in the schema which will act as a db identifier for that document\n```node\nconst likeSH = mongodb.Schema({\n  user_id: { type: mongoose.Schema.Types.ObjectId, required: true, ref: \"users\" },\n  postId: { type: mongoose.Schema.Types.ObjectId, required: true  },\n  dbIndex: { type: Number, required: true },\n\n  like_time: { type: Date, default: Date.now }\n}\n)\n```\n### model building\n```node\nconst likes = mongodb.buildModel(\"likes\", likeSH)\n```\n\n\n##### Note that `dbIndex` is used to indicate which MongoDB server it belongs to.\n###### it is a must otherwise it will throw an error.\n```node\n     throw new Error(`[!]Error :  \u003c dbIndex \u003e must be present in your schema like dbIndex:{\n            type: Number,\n            required: true\n          } `)\n```\n\n\n### usage methods\n```node \nfindInAllDatabase(filter, chain = {})\n```\nUsage: Finds documents matching the filter in all MongoDB databases.\n\n```node \nconst result = await likes.findInAllDatabase({ name: 'John' }, { limit: 10, skip: 0 });\nReturns: An array of documents matching the filter from all databases.\n```\n```node\nwriteInAllDatabase(data)\n\nUsage: Writes data to all MongoDB databases.\n\nconst result = await likes.writeInAllDatabase({ name: 'John', age: 30 });\nReturns: An array of written documents from all databases.\n```\n```node\nUpdateOneInAllDatabase(filter, update)\nUsage: Updates a single document matching the filter in all MongoDB databases.\nconst updatedDocument = await likes.UpdateOneInAllDatabase({ name: 'John' }, { age: 35 });\nReturns: The updated document.\n```\n```node \nUpdateByIdInAllDatabase(id, update)\nUsage: Updates a document by ID in all MongoDB databases.\nconst updatedDocument = await likes.UpdateByIdInAllDatabase('123456', { age: 35 });\nReturns: The updated document.\n```\n```node \nfindByIdInAllDatabaseAndDelete(id)\nUsage: Finds a document by ID in all MongoDB databases and deletes it.\nconst deletedDocument = await likes.findByIdInAllDatabaseAndDelete('123456');\nReturns: The deleted document.\n```\n\n```node \nfindOneInAllDatabaseAndDelete(filter)\nUsage: Finds a single document matching the filter in all MongoDB databases and deletes it.\nconst deletedDocument = await likes.findOneInAllDatabaseAndDelete({ name: 'John' });\nReturns: The deleted document.\n```\n```node \nwrite(data)\nUsage: Writes data to a MongoDB database.\nconst result = await likes.write({ name: 'John', age: 30 });\nReturns: The written document.\n```\n\n```node \nbulkWrite(data)\nUsage: Bulk writes data to a MongoDB database with transaction inbuilt.\n\n const testData = Array.from({ length: 10000 }, (_, i) =\u003e ({\n        name: `User ${i}`,\n        email: `user${i}@example.com`,\n        age: 20 + (i % 50)\n    }));\n\n    // Test 1: Large batch, concurrent\n    console.time('Large batch concurrent');\n    await UserModel.bulkWrite(testData, {\n        batchSize: 5000,\n        concurrentBatches: true\n    });\n```\n\n```node \nfindOne(dbIndex, filter, chain = {})\nUsage: Finds a single document matching the filter in a specific MongoDB database.\nconst document = await likes.findOne(0, { name: 'John' }, { limit: 1 });\nReturns: The found document.\n```\n```node\nfind(dbIndex, filter, chain = {})\nUsage: Finds documents matching the filter in a specific MongoDB database.\nconst documents = await likes.find(0, { age: { $gt: 18 } }, { limit: 10 });\nReturns: An array of found documents.\n```\n\n```node \nfindById(dbIndex, id, chain = {})\nUsage: Finds a document by ID in a specific MongoDB database.\nconst document = await likes.findById(0, '123456');\nReturns: The found document.\n```\n```node\nfindByIdAndUpdate(dbIndex, id, update)\nUsage: Finds a document by ID in a specific MongoDB database and updates it.\nconst updatedDocument = await likes.findByIdAndUpdate(0, '123456', { age: 35 });\nReturns: The updated document.\n```\n```node\nfindByIdAndDelete(dbIndex, id)\nUsage: Finds a document by ID in a specific MongoDB database and deletes it.\nconst deletedDocument = await likes.findByIdAndDelete(0, '123456');\nReturns: The deleted document.\n```\n```node\nfindOneAndUpdate(dbIndex, filter, update)\nUsage: Finds a single document matching the filter in a specific MongoDB database and updates it.\n\nconst updatedDocument = await likes.findOneAndUpdate(0, { name: 'John' }, { age: 35 });\nReturns: The updated document.\n```\n```node\naggregate(dbIndex, filter)\nUsage: Aggregates documents in a specific MongoDB database based on the filter.\nconst aggregationResult = await likes.aggregate(0, [{ $group: { _id: '$name', total: { $sum: '$age' } } }]);\nReturns: The aggregation result.\n```\n```node\nwatch(dbIndex)\nUsage: Starts watching for changes in a specific MongoDB database.\nconst watcher = await likes.watch(0);\nReturns: A watcher object for the database.\n```\n\n\u003e now most of the functionality is as same as mongoose  so you can use them directly like indexing a schema \n```node\nlikeSH.index({ user_id: 1, postId: 1 }, { unique: true });\n```\n# Contributing\nthere are many things that are not ported. feel free to contribute!\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update.and also ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktbsomen%2Fmongoplusplus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktbsomen%2Fmongoplusplus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktbsomen%2Fmongoplusplus/lists"}