Closed trusktr closed 8 years ago
How do we do anything in before.upsert? There's no doc
argument to validate individual docs, like with the other hooks. For example, how do we do the upsert in the following?
collection.before.insert((userId, doc) => {
checkAgainstSchema(doc, schema)
})
collection.before.update((userId, doc, fieldNames, modifier, options) => {
checkAgainstSchema(doc, schema)
})
collection.before.upsert(function(userId, selector, modifier, options) {
// ???
})
@matb33
Can you accomplish what you need with allow/deny? http://docs.meteor.com/#/basic/Mongo-Collection-allow
I could, but I think the hooks are a nicer pattern for this, in general. I found a solution: use LocalCollection
from minimongo
. We can get the documents (if any) using the selector
, then transform them to their new state with LocalCollection._modify
, and finally check the modified documents before they are actually sent to the DB.
?