1

Is it possible to apply a modifier to a document and see the result before doing the actual update query?

Something like a virtual/simulated update.

My purpose is to validate any possible update inside a before hook through an external service that only accepts some final, post-operation document and then possibly abort the operation.

dalgard
  • 3,614
  • 2
  • 22
  • 28
  • did you mean some thing like commit rollback in mysql? – pahan Apr 30 '15 at 10:11
  • I'm thinking something like transforming a document object in accordance with the contents of a modifier object too see that the new document looks like. – dalgard Apr 30 '15 at 10:19

2 Answers2

1

Minimongo has a function that can be used: LocalCollection._modify(doc, modifier). In order to load LocalCollection on the server, add minimongo to local/packages

dalgard
  • 3,614
  • 2
  • 22
  • 28
0

write your logic for logic inside a allow,deny function

update(userId, doc, fieldNames, modifier)

fieldNames is an array of the (top-level) fields in doc that the client wants to modify, for example ['name', 'score'].

modifier is the raw Mongo modifier that the client wants to execute; for example, {$set: {'name.first': "Alice"}, $inc: {score: 1}}.

Posts.allow({
  update: function (userId, doc, fields, modifier) {
    //you can return false here, if you dont want to update db
  },
});
pahan
  • 2,445
  • 1
  • 28
  • 36