{"id":26882593,"url":"https://github.com/zackurben/update-mongo","last_synced_at":"2026-04-28T20:03:21.825Z","repository":{"id":34754784,"uuid":"38735882","full_name":"zackurben/update-mongo","owner":"zackurben","description":"An easy way to run MongoDB update stripts in Node.","archived":false,"fork":false,"pushed_at":"2015-07-18T16:37:59.000Z","size":136,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-19T19:41:42.963Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zackurben.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-08T06:18:29.000Z","updated_at":"2015-07-08T06:26:04.000Z","dependencies_parsed_at":"2022-09-15T06:20:58.491Z","dependency_job_id":null,"html_url":"https://github.com/zackurben/update-mongo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackurben%2Fupdate-mongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackurben%2Fupdate-mongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackurben%2Fupdate-mongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackurben%2Fupdate-mongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zackurben","download_url":"https://codeload.github.com/zackurben/update-mongo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246326604,"owners_count":20759436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-03-31T16:38:56.428Z","updated_at":"2026-04-28T20:03:16.802Z","avatar_url":"https://github.com/zackurben.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# update-mongo\nA simple Node.js Module to run updates for [MongoDB](https://www.mongodb.org/).\n\n# About\nAll commands in the Mongo shell are synchronous and therefore simple to control the flow of execution, but that is not the case with the Native Node.js Driver. Using the `update-mongo` interface, you can easily write scripts for the mongo shell and run them during code execution.\n\n update-mongo allows you to run update scripts for MongoDB without interacting with the [Mongo DB Native NodeJS Driver](https://github.com/mongodb/node-mongodb-native). This is an open source project under the MIT license, see [LICENSE.md](LICENSE.md) for additional information.\n\n **Skip to [Examples](#example) on how to use `update-mongo`**\n\n# Installation\n```\nnpm install --save update-mongo\n```\n\n# Usage\nOne method is provided: `updates.run(scripts, callback);`\n\nSee [Scripts](#scripts) for more information on how the scripts are loaded.\nThe callback function takes two parameters:\n```javascript\nvar callback = function(error, info) {};\n```\n\nBasic usage is as follows:\n```javascript\nvar updates = require('update-mongo')(options);\n\n// Run the given update scripts in order, then execute the given callback function.\nupdates.run(scripts, callback);\n```\n\n# Options\nThe options are given as an object upon loading `update-mongo`. The only required option is, `db`, which defines the database the updates will be run against.\n\n```javascript\nvar updates = require('update-mongo')(options);\n```\n\n```javascript\nvar options = {\n  db: '',     // String [required] - The database to connect to and perform updates.\n  prefix: '', // String - The string to affix before each given update file.\n  suffix: ''  // String - The string to affix after each given update file.\n};\n```\n\n# Scripts\nThe scripts provided to `updates.run()` can be provided in a few different ways: and array of strings (script file names) to run in-order, a combination of JavaScript functions and strings, or an array of the previous.\n\n__Note: When functions are supplied, the require a single parameter, a callback function, which will be called when the function is complete.__\n\nPossible combinations follow:\n```javascript\n// The order of execution in this example is: script1, script2, script3\nupdates.run([\n  './script1',\n  './script2',\n  './script3'\n], callback);\n\n// The order of execution in this example is: function A, script2, function B\nupdates.run([\n  function A(done) { done(); },\n  'script2',\n  function B(done) { done(); }\n], callback);\n\n// The order of execution in this example is: script1, function A, script2,\n// function B, script3\nupdates.run([\n  './script1',\n  [\n    function A(done) { done(); },\n    './script2',\n    function B(done) { done(); }\n  ],\n  './script3'\n], callback);\n```\n\nIf a String is given in the scripts array, `update-mongo` will look for the file given by:\n```\noptions.prefix + script + options.suffix\n```\n\nExample\n```javascript\n// The Script to run:  ./scripts/script1.js\n\nvar updates = require('update-mongo')({\n  db: 'foo',\n  prefix: './scripts/',\n  suffix: '.js'\n});\n\nupdates.run([\n  'script1'\n], callback);\n```\n\n# Example\n```javascript\nvar updates = require('update-mongo')({\n  db: 'some-test-db'\n});\n\n// Run the given update scripts in order, then execute the given callback function.\nupdates.run([\n  './script1',\n  './script2',\n  './script3'\n], function() {\n  // Do something when all updates are complete.\n  console.log('Done running update scripts1-3');\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackurben%2Fupdate-mongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzackurben%2Fupdate-mongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackurben%2Fupdate-mongo/lists"}