cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Grouping of commonly related entities

I have entity types A and B that have a many to many relationship in my db .
I wish to trigger an event upon the change in the members of any groups of entity B with a common set or relationships to entity type As.
e.g.
we have A(1) A(2) A(3), and B(1) B(2) B(3)
if we insert the following relationships
A(1)->B(1)
A(1)->B(2)
A(1)->B(3)

A(2)->B(1)
A(2)->B(2)

we have 2 groups,
G(1)= B(1) and B(2) both have the commons set of relations to A(1) AND A(2) ,
G(2) = B(3) the second group containing only relations to A(1) and nothing else

if we add
A(3)->B(2)
A(3)->B(3)

we now have three groups all containing just one B,
and G(2), created on the initial insert, is now empty but still requires an event
G(1)=B(1)
G(2)=<EMPTY<
G(3)=B(2)
G(4)=B(3)

I want an event for each of those four groups

Currently I do this by hashing the set of As belonging to any B and then group the Bs on that value

I perform these inserts in massive blocks (100,000 As each with ab average of over 100 Bs) so its efficient enough, but the code is hell of course. I have to instantiate the groups as entities in my DB as they form, and ensure that all groups affected get an event.

Can you help ?

3 REPLIES 3

Have you checked out APOC Triggers? I'm not sure by what you mean by "event" but you can program a trigger to happen after a transaction like we're familiar in doing in RDBMS.

triggers should do the job yer. but i have jmy head in a rdbms world, do i need to instantiate a "group" entity ? i dont care, all i want it to do is say "the grouping of As X,Y&Z has just changed"

i could apply the A-<B relationship and recalculate the group hash, and iate a group if missing, but then i am goig to trigger changes on these groups on every insert, there re, literally , millions. i only want to execute the triggers after the batch insert. with rdbms i just set a flag in the table and go select groups where status=publish. I am wondering if i have to stick with my rdbms and my simplified but still extensive set of operations.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online