A Node.js library (v2.0.0, 2024) that converts RFC 6902 JSON Patch operations into a sequence of MongoDB update operations. It builds on rfc6902 and the standard mongodb driver, producing commands suitable for collection.updateOne(). Differs from similar tools by explicitly not supporting full-document replacement, array root targets, or empty keys; it also coalesces operations when safe but errs on correctness. Requires Node >=20 and is ESM-only. Low monthly downloads; niche utility for developers applying JSON Patches to MongoDB documents.
npm install rfc6902-mongodbNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to MongoDB, inserts a document, applies a JSON Patch via updatesForPatch() using async iteration, and performs each MongoDB update in order.
Use import statement or dynamic import(). Ensure package.json has 'type': 'module' if needed.
Upgrade Node.js to v20 or newer.
Avoid patches with {'path': ''} for replace operations; instead use MongoDB replaceOne directly.Fetch the document immediately before calling updatesForPatch; consider using transactions or optimistic locking.
Validate or sanitize patch paths and values to avoid these characters before calling updatesForPatch.
Use the library in a controlled environment or apply updates sequentially on a single connection.
Change to 'import { updatesForPatch } from 'rfc6902-mongodb';' or use dynamic import: 'const { updatesForPatch } = await import('rfc6902-mongodb');'Use named import: import { updatesForPatch } from 'rfc6902-mongodb';Ensure the MongoDB document at the root is an object (nested arrays are fine). Pass an object document to updatesForPatch.
Use MongoDB's replaceOne() instead of updatesForPatch for full-document replacement. Remove such patch operations.
Remove or escape '$', '.', '\0' from paths/values before creating the patch. For example, use '\$' as a literal if needed.