{"id":27786337,"url":"https://github.com/clever/mongo-lock-node","last_synced_at":"2026-03-05T11:32:35.058Z","repository":{"id":18224310,"uuid":"83834943","full_name":"Clever/mongo-lock-node","owner":"Clever","description":"Implements a distributed lock client backed by mongo","archived":false,"fork":false,"pushed_at":"2025-11-05T22:49:30.000Z","size":234,"stargazers_count":3,"open_issues_count":4,"forks_count":3,"subscribers_count":47,"default_branch":"master","last_synced_at":"2025-11-06T00:19:38.349Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":false,"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/Clever.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":"2017-03-03T19:44:00.000Z","updated_at":"2025-11-05T22:49:34.000Z","dependencies_parsed_at":"2024-05-06T20:36:11.645Z","dependency_job_id":"8dc33d27-5b0e-477c-b47d-b785809864cb","html_url":"https://github.com/Clever/mongo-lock-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Clever/mongo-lock-node","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fmongo-lock-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fmongo-lock-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fmongo-lock-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fmongo-lock-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clever","download_url":"https://codeload.github.com/Clever/mongo-lock-node/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clever%2Fmongo-lock-node/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30122146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T11:11:57.947Z","status":"ssl_error","status_checked_at":"2026-03-05T11:11:29.001Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":[],"created_at":"2025-04-30T15:59:45.305Z","updated_at":"2026-03-05T11:32:35.039Z","avatar_url":"https://github.com/Clever.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongo-lock-node\n\nDistributed lock client backed by mongo.\n\n## Installation\n```\n#\u003e npm install --save mongo-lock-node\n```\n\n## Usage\n```javascript\nimport * as MongoClient from \"mongodb\";\nimport {RWMutex} from \"mongo-lock-node\";\n\n// connect to mongo\nconst db = await MongoClient.connect(\"mongodb://localhost:27017/test\");\nconst collection = db.collection(\"locks\");\nawait collection.createIndex(\"lockID\", { unique: true });\n\n// create a client\nconst lockID = \"lock_1\"; // must be unique per lock\nconst clientID = \"client_1\"; // must be unique per client\nconst lock = new RWMutex(collection, lockID, clientID);\n\n// acquire the write lock\ntry {\n  await lock.lock();\n} catch (err) {\n  // other try/catch blocks omitted for brevity\n  console.error(err.message); // =\u003e \"error acquiring lock lock_1: connection interrupted\"\n  throw err;\n}\n// no other clients acquire a read or write lock while you have the write lock\nconsole.log(\"doing important things...\");\n// release the write lock\nawait lock.unlock();\n\n// acquire the read lock\nawait lock.rLock();\n// other clients can also acquire a read lock, no clients can acquire the write lock\nconsole.log(\"reading important things...\");\n// release the read lock\nawait lock.rUnlock();\n```\n\n## Gotchas\nThe current implementation is limited in a few ways. We may address these issues in the future but\nright now you should be aware of them before using this library:\n\n1. Re-enterable locks. RWMutex treats a clientID already existing on the lock in the db as a\n   lock that this client owns. It re-enters the lock and proceeds as if you have the lock.\n2. No heartbeat. Our current requirements for this project do not include heartbeats, so any\n   client that does not call unlock will remain on the lock forever.\n3. Manual setup. This library does not currently support setup. The collection you pass to the\n   constructor must have a unique index on the `lockID` field.\n\n## Testing\n```\nmake test\n```\n\n## Building for local use\n```\n# This will compile lib/ to javascript in the dist/ folder\nmake build\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclever%2Fmongo-lock-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclever%2Fmongo-lock-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclever%2Fmongo-lock-node/lists"}