Datastore ds = datastore;
Query<Document> query = ds.createQuery(Document.class).field("_id").equal(documentId);
UpdateOperations<Document> ops = ds.createUpdateOperations(Document.class).set("draft.languages", draft);
ds.update(query, ops);
this is the class i'm trying to change
@Embedded("language")
private String language;
private String body;
json before:
"languages" : [
{
"language" : "en",
"body" : "bla blaaaaaaaaaaaa ttttttt"
},
{
"language" : "ru",
"body" : "faksdfsdghfhshsssssssssh"
}
]
json after:
"languages" : [
{
"language" : "en",
"body" : "bla blaaaaaaaaaaaa ttttttt"
},
{
"language" : "ru",
"body" : "faksdfsdghfhshsssssssssh"
},
{
"language" : "en",
"body" : "blablablablalblalaakfslkdfjkldf"
}
]
draft is list of languages
i'm trying to do an update if the language exists in the draft segmant, or insert new one, the problem is the body is different so it always inserts new one instead of replacing the old one. i think i'm missing something(i used $addtoset and it added the list instead of replacing)
for now i'm using set and replacing the whole list, is there a better option?
thanks for your help!
example for what i'm trying to do
json before
insert
"languages" : [
{
"language" : "en",
"body" : "bla blaaaaaaaaaaaa"
},
{
"language" : "it",
"body" : "faksdfsdghfhshsssssssssh"
}
]
i expect the result will be:
"languages" : [
{
"language" : "en",
"body" : "bla blaaaaaaaaaaaa"
},
{
"language" : "ru",
"body" : "faksdfsdghfhshsssssssssh"
},
{
"language" : "it",
"body" : "faksdfsdghfhshsssssssssh"
}
]