{"id":15763021,"url":"https://github.com/junzhengca/mongoose-document-lock","last_synced_at":"2026-05-01T08:32:22.302Z","repository":{"id":57302249,"uuid":"154970901","full_name":"junzhengca/mongoose-document-lock","owner":"junzhengca","description":"Redis or In-Memory Document Lock for Mongoose","archived":false,"fork":false,"pushed_at":"2018-10-27T16:12:47.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-15T02:58:50.642Z","etag":null,"topics":["lock","mongodb","mongoose","nosql","plugin","redis"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junzhengca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-27T14:02:02.000Z","updated_at":"2018-10-29T16:54:18.000Z","dependencies_parsed_at":"2022-09-14T22:55:25.510Z","dependency_job_id":null,"html_url":"https://github.com/junzhengca/mongoose-document-lock","commit_stats":null,"previous_names":["junthehacker/mongoose-document-lock"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/junzhengca/mongoose-document-lock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junzhengca%2Fmongoose-document-lock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junzhengca%2Fmongoose-document-lock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junzhengca%2Fmongoose-document-lock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junzhengca%2Fmongoose-document-lock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junzhengca","download_url":"https://codeload.github.com/junzhengca/mongoose-document-lock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junzhengca%2Fmongoose-document-lock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32490810,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","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":["lock","mongodb","mongoose","nosql","plugin","redis"],"created_at":"2024-10-04T11:40:22.670Z","updated_at":"2026-05-01T08:32:22.285Z","avatar_url":"https://github.com/junzhengca.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongoose Document Lock\n\nEasy to use document lock plugin for mongoose. Both in-memory lock and Redis lock.\n\nIf you are implementing this lock, it is usually a good idea to remove the `versionKey` field in your schema, since you don't need an optimistic lock if you are using this library.\n\n## Install\n\n```\n$ npm install mongoose-schema-lock\n```\n\n\u003e Unfortunately mongoose-document-lock is taken :(\n\nThen in your code\n\n```js\nmongoose.plugin(require('mongoose-schema-lock'));\n```\n\nBy default, locks will be stored in-memory, if you wish to use Redis, you can pass an `node_redis` client instance in config (more on this later).\n\n## Basic Usage\n\nTo lock a document, simply call `document.lock(callback)`.\n\n```javascript\nUser.findOne({name: \"Jun\"}, function(err, user) {\n    user.lock(function(release) {\n        // Do you stuff here\n        release();\n    })\n})\n```\n\nOnce you lock a document, no other `.lock` calls will be able to obtain the lock for that specific document until you call `release()`.\n\nYou can find some demos within `/demo` folder.\n\n## Use Promises\n\nYou can choose to use promises instead of callbacks, to do this, simply pass `promise: true` in configurations.\n\n```javascript\nmongoose.plugin(require('mongoose-schema-lock'), {promise: true});\n\nUser.findOne({name: \"Jun\"}, function(err, user) {\n    user.lock().then(lock =\u003e {\n        // Do your sutff\n        lock.release();\n    })\n})\n```\n\n## Use Redis\n\nIf you have multiple servers load-balanced, or wish to share locks across applications, you might want to use Redis.\n\nTo use Redis, simply pass a Redis client in configurations.\n\n```javascript\nconst redis = require(\"redis\"),\n      client = redis.createClient();\n\nmongoose.plugin(require('../index'), {redis: client});\n```\n\n## Configurations\n\n```\n{\n    redis: node_redis.client, // If this is set, locks will use Redis instead of in-memory\n    promise: Boolean // If true, lock() will return a promise instead\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunzhengca%2Fmongoose-document-lock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunzhengca%2Fmongoose-document-lock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunzhengca%2Fmongoose-document-lock/lists"}