Kindth
Kindth

Reputation: 337

How to update only attributes that have changed - Spring MVC mongoDB

I'm using Spring Data MongoDB and Spring Data Rest to create a REST API which allows GET, POST, PUT and DELETE operations on my MongoDB database and it's all working fine except for the update operations (PUT). It only works if I send the full object in the request body otherwise variables didn't send it in the rquest are null.Can someone guide me to solve this.

@PutMapping("/update/{id}")
    public void update(@Valid @RequestBody Facture facture, @PathVariable("id") String id){
        Optional<Facture> factureData = factureRepository.findById(id);

            facture.setId_facture(id);
            this.factureRepository.save(facture);
}

Upvotes: 1

Views: 209

Answers (1)

Omar Ajmi
Omar Ajmi

Reputation: 190

you could try a object comparison library like javer

Upvotes: 1

Related Questions