A hook that is triggered before an insert()
operation.
The beforeInsert()
hook runs when:
insert()
function is called.The hook also runs when an action is performed on a dataset that inserts a new item into the collection that the dataset is connected to.
Return an object or a Promise that resolves to an object from the beforeInsert()
function. The returned object will be inserted into the collection instead of
the original item passed to the insert()
function.
If the returned value is of the wrong type, the value is ignored.
A rejected Promise blocks the call to insert()
and also calls the onFailure()
hook if it has been registered.
Because the beforeInsert()
hook is called before insert()
is executed, it can affect the item that is inserted into the collection
or block the insert()
.
The original item to be inserted.
Contextual information about the hook.