Trying to update meta fields with Type . merge

#1

I’m trying to manage Change Data Capture and need to update/create meta fields via merge. For some reason I’m not able to change the meta.updated timestamp. It will create the meta.sourceSystem but I won’t be able to update it.

Products.push(Product.make({
  id: serialNumber,
  meta: {sourceSystem: "MYSOURCE", updated:DateTime("2018-04-22T18:02:06.000Z") }
}));
Product.mergeBatch(Products);
0 Likes

#2

See MergeSpec.metaOverride. Documentation:

Indicates that the values of Meta#updated, Meta#updatedBy, Meta#created and Meta#createdBy will be used if they are present. Otherwise they will be defaulted to the current time and user making the request.

0 Likes

#3

Is there a way to compare the timestamps to make a change based on meta.updated?

0 Likes

#4

I don’t think you can do that in a single action, but you could fetch first with a filter on meta.updated.

0 Likes

#5

Is metaOverride working in v7.6.1? I tried it with merge, update and upsert but it seems to be ignored.
Thanks

0 Likes

#6

Thanks to @bachr, the trick to update meta.created is (in addition to using metaOverride) is to set meta.updated too. In the result, the new meta.updated is ignored, but meta.created is updated. This is so in v7.6.1.

0 Likes