Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

341
Views
How to compare API request JSON with existing json document in MongoDb?

The title of the question is self explanatory. I want to know what differences are there in JSON Document A which comes from API request and JSON Document B which is already in Mongo DB.how to get changes column name and data also.. i am creating log..that's why i want... Below is the code of what I'm trying:

NodeJS APICode//

 function Updatejob(req, res) {
      return function (jobSchedule) {
        var obj = new Date();

        CompareJSON(req, mongodbjson); 
        return Job.create(req.body).then(.....)
        }

Already Data in Mongodb before Update Record

{
    "_id" : ObjectId("586d1032aef194155028e9c7"),
  "history" : [ 
        {
            "_id" : ObjectId("586d1032aef194155028e9c4"),
            "updated_by" : "",
            "details" : "Job Created",
            "changetype" : "Created",
            "datetime" : ISODate("2017-01-04T15:09:38.465Z")
        }
    ],
 "current_status" : "Pending",
    "time" : 0
}

//REQUEST FOR UPDATE DATA

  {
        "_id" : ObjectId("586d1032aef194155028e9c7"),
      "history" : [ 
            {
                "_id" : ObjectId("586d1032aef194155028e9c4"),
                "updated_by" : "",
                "details" : "Job Completed",
                "changetype" : "Completed",
                "datetime" : ISODate("2017-01-04T15:09:38.465Z")
            }
        ],
     "current_status" : "Completed",
        "time" : 0
    }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use jsondiffpatch:

 var delta = jsondiffpatch.diff(object1, object2);

See:

  • https://www.npmjs.com/package/jsondiffpatch
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!