Convert JSON Patch (RFC 6902) operations into MongoDB update documents. Version 1.0.0 provides a single function that translates an array of JSON patch operations (add, remove, replace, move, copy, test) into a MongoDB-compatible update object with $set, $unset, $push, $pull, etc. No release cadence specified; actively maintained by MongoDB.js team. Differentiators: lightweight, no external dependencies, designed specifically for MongoDB update generation.
npm install jsonpatch-to-mongodbNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Converts two JSON patch operations (replace and add) into a MongoDB update object with $set and $push operators.
Ensure patches are in the correct order (e.g., remove before replace at same path).
Remove test operations before passing to toMongodb, or handle them separately.
Validate paths with a JSON Pointer library or ensure they start with '/'.
Add a declaration file: declare module 'jsonpatch-to-mongodb' { function toMongodb(patches: any[]): any; export default toMongodb; }Use default import: import toMongodb from 'jsonpatch-to-mongodb' or const toMongodb = require('jsonpatch-to-mongodb').Remove test operations from patch array before calling toMongodb, or implement custom handling.
Ensure each patch has a valid 'path' string property (e.g., '/name').
No dependency data recorded yet.