所以我正在尝试创建一组查询,在给定节点列表的情况下执行以下操作:
我的第一次尝试就是这两个问题:
MATCH (u:User) WHERE u.id IN {userIds}
WITH collect(u) as users
MATCH (conversation:Conversation)
WHERE ALL(u in users WHERE (u)-->(conversation))
RETURN conversation
MATCH (user:User) WHERE user.id IN {userIds}
MERGE (conversation:Conversation {id: {conversationId}})
WITH conversation
MERGE (user)-[:In]->(conversation)
RETURN conversation
但结果是为每个用户节点创建了一个会话节点,我想要的是一个连接到所有用户节点的会话节点。
我怎样才能做到这一点?
在你的WITH
子句中,你需要传递用户:
MATCH (user:User) WHERE user.id IN {userIds}
MERGE (conversation:Conversation {id: {conversationId}})
WITH conversation, user
MERGE (user)-[:In]->(conversation)
RETURN conversation