Search code examples
memgraphdb

How to create a trigger whenever a new node is being created?


I want to create a trigger that activates whenever a new node is created.

Here’s the scenario: imagine I’m building a social network application where users can create profiles. Whenever a new user profile node is created, I want to automatically create an associated "welcome message" node and link it to the new user node. This way, every new user automatically gets a welcome message upon creation.

I saw I can create a custom module, but I was wondering if the logic of a trigger should be included in the module itself.


Solution

  • There are ON CREATE, ON UPDATE and ON DELETE triggers, and every event type has predefined variables that you can use in the following part of the query. Ideally, once you have those predefined variables, use them in the rest of the Cypher queries. If you can’t write your query with Cypher, create a custom query module.