{"id":50559005,"url":"https://github.com/pier4all/mongoose-versioned","last_synced_at":"2026-06-04T10:03:37.436Z","repository":{"id":40994174,"uuid":"375302334","full_name":"pier4all/mongoose-versioned","owner":"pier4all","description":"Document versioning library for MongoDB using the mongoose package.","archived":false,"fork":false,"pushed_at":"2023-12-08T10:40:15.000Z","size":540,"stargazers_count":15,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-11T15:44:13.082Z","etag":null,"topics":["data-versioning","mongo","mongodb","mongoose","versioning"],"latest_commit_sha":null,"homepage":"","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/pier4all.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-09T09:40:35.000Z","updated_at":"2025-08-27T12:27:33.000Z","dependencies_parsed_at":"2023-01-29T21:45:47.900Z","dependency_job_id":null,"html_url":"https://github.com/pier4all/mongoose-versioned","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pier4all/mongoose-versioned","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pier4all%2Fmongoose-versioned","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pier4all%2Fmongoose-versioned/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pier4all%2Fmongoose-versioned/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pier4all%2Fmongoose-versioned/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pier4all","download_url":"https://codeload.github.com/pier4all/mongoose-versioned/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pier4all%2Fmongoose-versioned/sbom","scorecard":{"id":733266,"data":{"date":"2025-08-11","repo":{"name":"github.com/pier4all/mongoose-versioned","commit":"7bb41bd06273f2c2b3b1a3aa3d8470910dc27f01"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"17 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-x3cc-x39p-42qx","Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22","Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-vxvm-qww3-2fh7","Warn: Project is vulnerable to: GHSA-9m93-w8w6-76hh","Warn: Project is vulnerable to: GHSA-m7xq-9374-9rvx","Warn: Project is vulnerable to: GHSA-vg7j-7cwx-8wgw","Warn: Project is vulnerable to: GHSA-rxrc-rgv4-jpvx","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-22T15:02:04.691Z","repository_id":40994174,"created_at":"2025-08-22T15:02:04.691Z","updated_at":"2025-08-22T15:02:04.691Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33899755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-04T02:00:06.755Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["data-versioning","mongo","mongodb","mongoose","versioning"],"created_at":"2026-06-04T10:03:36.581Z","updated_at":"2026-06-04T10:03:37.425Z","avatar_url":"https://github.com/pier4all.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Versioning Module MongoDB\nModule for versioning in MongoDB, inspired by Vermongo (https://www.npmjs.com/package/mongoose-vermongo, https://github.com/codela/mongoose-vermongo and https://github.com/thiloplanz/v7files/wiki/Vermongo).\n\nIt includes support for transactions to avoid inconsistency when performing an update or deletion since this operations involve the main and the shadow collection (see instructions below).\n\nThis module allows to keep the change history of every document and the deleted documents. The idea is to have a \"main collection\" storing the current document versions and a different collection called \"shadow collection\" to keep all the past versions and deleted documents.\n\nSee Basic Usage.\n\n### Use\nIn order to use the package just install it as a dependency\n```\nnpm install mongoose-versioned\n```\n\n### Basic usage\nThis package requires mongoose and it is added as a plugin to each individual model that will be versioned. Get familiar with mongoose before using this package (https://mongoosejs.com/docs/index.html).\n\n```javascript\n// import versioning and mongoose related dependencies\nconst versioning = require('mongoose-versioned')\nconst constants = require('mongoose-versioned/source/constants')\n\nconst mongoose = require('mongoose')\nmongoose.Promise = require('bluebird')\nlet Schema = mongoose.Schema\n\n// connect to the database following mongoose instructions, for example:\nlet mongodb_uri = 'mongodb://localhost/test'\n\nconst versionItems = async(mongodb_uri) =\u003e {\n  try {\n      await mongoose.connect(mongodb_uri, { useUnifiedTopology: true, useNewUrlParser: true, useFindAndModify: false })\n      console.log(\"Database.connect: DB connected \")\n  } catch (err) {\n      console.error(`Database.connect: MongoDB connection error. Please make sure MongoDB is running:` + err.message)\n      throw new Error(err)\n  }\n\n  const db = mongoose.connection\n\n  // create the model\n  let itemSchema = new Schema({\n    code: { type: Number, required: true, unique: true },\n    name: { type: String, required: true, unique: false }\n  })\n\n  // add the versioning plugin to the schema and specify\n  // the name of the shadow collection\n  const name = 'item'\n  itemSchema.plugin(versioning, {collection: name + \"s.versioning\", mongoose})\n\n  // instantiate the model\n  let Item = mongoose.model(name, itemSchema)\n  // at this point a collection named 'tests'\n\n  // add a new document\n  const newItem = {\n    code: 1,\n    name: \"first item\"\n  }\n\n  let savedItem = await new Item(newItem).save()\n  console.log(`saved item with id: ${savedItem._id}, version: ${savedItem._version}`)\n\n  let id = savedItem._id\n\n  // update document info\n  savedItem.name = \"modified item\"\n\n  // add edition information\n  savedItem[constants.EDITOR] = \"editing user\"\n  \n  // perform the update\n  let updatedItem = await savedItem.save()\n  console.log(`updated item with name: ${updatedItem.name}, version: ${updatedItem._version}`)\n\n  // find current version\n  let foundCurrent = await Item.findVersion(id, 2, Item)\n  console.log(`found current version ${foundCurrent._version}, name = ${foundCurrent.name}`)\n\n  // find old version\n  let foundOld = await Item.findVersion(id, 1, Item)\n  console.log(`found current version ${foundOld._version}, name = ${foundOld.name}`)\n\n  await db.close()\n}\n\nversionItems(mongodb_uri)\n\n```\n\n### Using transactions\nTransactions\n\nTransactions can be used to ensure the database remains in a consistent state even if the operation fails. Update and delete operations involve changes in both main and shadow collections and therefore need to be wrapped in a transaction to ensure serialization.\n\nThe transaction should be stated before calling the update/delete operation and in addition the session should be stored in a reserved \"_session\" inside the document and passed as an option to save/delete method.\n\n```javascript\nconst versioning = require('mongoose-versioned')\nconst constants = require('mongoose-versioned/source/constants')\n\nconst mongoose = require('mongoose')\nmongoose.Promise = require('bluebird')\n\n[...]\n\ntry {\n  // start transaction\n  session = await mongoose.startSession()\n  session.startTransaction()\n\n  // store session in the document\n  document[constants.SESSION] = session\n\n  // save sending the session as option\n  await document.save({session})\n\n  // commit transaction\n  await session.commitTransaction()\n  session.endSession()\n\n} catch(error) {\n  if (session) session.endSession()\n  const message = `Error updating document ${id} in the collection ${collection}.`\n  processError(res, error, message)\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpier4all%2Fmongoose-versioned","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpier4all%2Fmongoose-versioned","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpier4all%2Fmongoose-versioned/lists"}