Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

337
Vistas
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 Respuestas
Responde la pregunta

0

You can use jsondiffpatch:

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

See:

  • https://www.npmjs.com/package/jsondiffpatch
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda