{"id":43779,"library":"rus-diff","title":"rus-diff","description":"A MongoDB-compatible JSON diff library that computes differences between two JSON objects and produces delta objects using MongoDB operators like $set, $unset, $rename, and $inc. Version 1.1.0 currently stable; low release cadence (last update 2015). Key differentiators: output directly usable with MongoDB collection.update(), supports incremental diffs via $inc option, and provides apply() to apply diffs without manual traversal. Suitable for syncing JSON documents or generating MongoDB update commands.","status":"maintenance","version":"1.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/mirek/node-rus-diff","tags":["javascript","json","diff","mongo","mongodb"],"install":[{"cmd":"npm install rus-diff","lang":"bash","label":"npm"},{"cmd":"yarn add rus-diff","lang":"bash","label":"yarn"},{"cmd":"pnpm add rus-diff","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import works since package is dual. CommonJS require also works.","wrong":"const diff = require('rus-diff').diff","symbol":"diff","correct":"import { diff } from 'rus-diff'"},{"note":"Named import for applying diff to an object.","symbol":"apply","correct":"import { apply } from 'rus-diff'"},{"note":"clone is a named export, not default.","wrong":"import clone from 'rus-diff'","symbol":"clone","correct":"import { clone } from 'rus-diff'"},{"note":"resolve is a named export, not a default function.","wrong":"const resolve = require('rus-diff').resolve","symbol":"resolve","correct":"import { resolve } from 'rus-diff'"}],"quickstart":{"code":"import { diff, apply, clone } from 'rus-diff';\n\nconst a = { a: 1, b: 'x', c: { d: 2 } };\nconst b = { a: 2, b: 'x', c: { d: 2 }, e: 3 };\n\nconst delta = diff(a, b);\nconsole.log(delta);\n// { $set: { a: 2, e: 3 }, $unset: { b: true } }\n\n// Apply delta (mutates a unless cloned)\nconst copy = clone(a);\napply(copy, delta);\nconsole.log(copy); // { a: 2, b: 'x', c: { d: 2 }, e: 3 }","lang":"typescript","description":"Shows diffing two objects and applying the delta with clone to avoid mutation."},"warnings":[{"fix":"Use apply(clone(a), delta) to avoid mutation.","message":"apply() mutates the target object in place. Always use clone(a) first if you want to preserve the original.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Manually compute numeric differences or use diff with { inc: true } but be aware it is not recommended for production.","message":"Options.inc (boolean) is deprecated and may be removed in future versions. Use explicit $inc handling instead.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"For arrays, consider manual comparison or a specialized diff library.","message":"The diff function does not detect array element moves; it treats arrays as atomic values. Use with caution for array-heavy documents.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use named imports like import { diff } from 'rus-diff' instead of default import.","message":"In version 1.1.0, the default export was removed. Import named exports only.","severity":"breaking","affected_versions":">=1.1.0"}],"env_vars":null,"search_vec":"'1.1.0':32 '2015':40 'appli':57,59 'cadenc':37 'collection.update':48 'command':73 'compat':7 'comput':12 'current':33 'delta':20 'diff':3,9,51,60,76 'differ':13 'differenti':42 'direct':44 'document':68 'generat':70 'inc':30,53 'increment':50 'javascript':74 'json':8,16,67,75 'key':41 'last':38 'librari':10 'like':25 'low':35 'manual':62 'mongo':77 'mongodb':6,23,47,71,78 'mongodb-compat':5 'object':17,21 'oper':24 'option':54 'output':43 'produc':19 'provid':56 'releas':36 'renam':28 'rus':2 'rus-diff':1 'set':26 'stabl':34 'suitabl':64 'support':49 'sync':66 'travers':63 'two':15 'unset':27 'updat':39,72 'usabl':45 'use':22 'version':31 'via':52 'without':61","created_at":"2026-06-05T17:01:26.465166+00:00","updated_at":"2026-06-05T17:01:26.465166+00:00","problems":[{"fix":"Use named import: import { diff } from 'rus-diff'","cause":"Using default import (import rusDiff from 'rus-diff') but package does not have default export in v1.1.0.","error":"TypeError: rus_diff_1.default is not a function"},{"fix":"Remove the require('babel/polyfill') line and use native ES6 features or add @babel/polyfill as a separate dependency.","cause":"Old documentation suggests require('babel/polyfill') which is not needed in modern environments.","error":"Cannot find module 'babel/polyfill'"},{"fix":"Call diff(a, b, [], { inc: true }) to enable $inc.","cause":"Passing { inc: true } to diff() is required to generate $inc operations for numeric changes.","error":"Delta contains $inc but was not set in options"},{"fix":"Apply $rename separately or use apply() which handles it correctly.","cause":"MongoDB does not allow $rename combined with $set, $unset in the same update object.","error":"Invalid update: $rename: { ... } is not allowed with other operators in same object"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/mirek/node-rus-diff","github":"git://github.com/mirek/node-rus-diff","docs":null,"changelog":null,"pypi":null,"npm":"rus-diff","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}