5

Is it possible to do an bulk upsert that behaves such that a particular field (e.g.: createdDT) is only set on first upsert, but not during later upserts of the same record?

EDIT

Got a crude version working which does a server-side executed loop, where for each element a lookup is followed by a conditional insert. Not the most elegant and likely pretty taxing performance wise. Any other options?

const tableName = "someTableName";
return r.expr(objs).forEach(function (docToInsert) {
      return r.table(tableName).get(docToInsert('id')).replace(function (existingDoc) {
        return r.branch(
          existingDoc.eq(null),
          r.expr(docToInsert).merge({ createdDT: r.now() }),
          existingDoc.merge(docToInsert)
        );
      });
    });

EDIT

It tags and title weren't clear: this question relates to rethinkDB

Geert-Jan
  • 18,623
  • 16
  • 75
  • 137

0 Answers0