i have sometimes the need to update many documents at once, 10K or even more, and I am thinking what is the advantage/disadvantage in each way?
I thought of two ways to do it, and I will happy to understand what is advantage/disadvantage and to to hear on a third way.
i am looking for a good batch way to do this.
way 1, send to observable to get all the documents and do the work:
Observable
.from(ids)
.flatMap(new Func1<String, Observable<JsonDocument>>() {
@Override
public Observable<JsonDocument> call(String id) {
return bucket.async().get(id);
}
})
.map(new Func1<JsonDocument, JsonDocument>() {
@Override
public JsonDocument call(JsonDocument original) {
// do some change in the document content
original.content().put("add", "content");
return original;
}
})
.flatMap(new Func1<JsonDocument, Observable<JsonDocument>>() {
@Override
public Observable<JsonDocument> call(JsonDocument modified) {
return bucket.async().replace(modified);
}
}).subscribe();
way 2, run on each document id and use async get and then change the document async way:
for (String id : ids){
bucket.async()
.get(id)
.map(new Func1<JsonDocument, JsonDocument>() {
@Override
public JsonDocument call(JsonDocument jsonDocument) {
// do some change in the document content
jsonDocument.content().put("add", "content");
return jsonDocument;
}
})
.flatMap(new Func1<JsonDocument, Observable<JsonDocument>>() {
@Override
public Observable<JsonDocument> call(JsonDocument modified) {
return bucket.async().replace(modified);
}
}).subscribe();
}