java - Spring-Data MongoDB Update all document fields -
i'm migrating sql (jpa) mongodb, , heard great things spring-data, i'm using it, whole conversion between dbobjects , application objects.
most of requirements met, don't know how migrate jpa's update functionality spring-data mongodb: 1. save/update implicit, handled hibernate 2. update updates values according given object
similarly jpa, when using com.mongodb.db can perform one-line "update" operation:
public boolean update(string collectionname, dbobject referenceobject, dbobject object) { writeresult result = this.db.getcollection(collectionname).update(referenceobject, object); return parsewriteresult(result); } it saves/updates object equals reference object according values in given object, , depending on whether object in db or not.
now i'm using mongooperations can update object using "update" object, have seed values 1 @ time:
mongooperations client = ... ... update update = new update(); update.set("past", 1); update.set("current", 3); ... client.updatefirst(query, update, clazz); is there way use functionality in jpa?
i not sure 100% understand question seems trying migrate data sql database using hibernate mongodb using spring-data.
we migrated of binary data in our application apache jackrabbit mongodb spring-data. in addition there 1 instance still storing binary data in our sql database migrated:
we migrated data in following manner:
- retrieve entities required hibernate.
- create new instance of mongodb document.
- loop through of these entities copying data hibernate entities onto mongodb document.
- call mongooperations#save() each document.
you mentioned updating:
to update particular document use mongooperations#updatefirst().
alternatively use mongooperatons#findone() object want, update fields want , call mongooperations#save() if read javadoc see performs upsert.
Comments
Post a Comment