合并查询:在创建时设置地图和"created"属性 [英] Merge query: set map and 'created' property upon creation

查看:97
本文介绍了合并查询:在创建时设置地图和"created"属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个尚不存在的用户,然后知道是否发生了创建.

I'm trying to create a user if it doesn't already exist, then know whether creation occurred or not.

此语法始终执行第二组:

This syntax always perform the second set:

MERGE (n:User {email: {email}})
ON CREATE n
  SET n = {user}
  SET n.created = timestamp()
WITH n WHERE n.created = timestamp()
RETURN n

我猜想第二组实际上不是ON CREATE子句的一部分,就像这样:

I'm guessing the second set isn't actually part of the ON CREATE clause, like so:

MERGE (n:User {email: {email}})
ON CREATE n
  SET n = {user}
SET n.created = timestamp()
WITH n WHERE n.created = timestamp()
RETURN n

但是,多个集合的替代语法导致出现错误:预期的有效查询正文":

However, the alternate syntax of multiple sets results in "Error: expected valid query body":

MERGE (n:User {email: {email}})
ON CREATE n
  SET n = {user}, n.created = timestamp()
WITH n WHERE n.created = timestamp()
RETURN n

作为一种解决方法,我决定将创建的时间戳与用户地图一起传递,但是有没有办法做到这一点?是按预期工作还是在这里存在错误?

As a workaround I've decided to pass the created time-stamp in with the user map, but is there a way to accomplish this? Is it working as intended or is there a bug here, maybe?

推荐答案

最后一个应该可以在IMO上工作-您能发出github问题吗?我们将看到新手说的话,但我认为以逗号分隔集应该没问题.

That last one should work IMO--can you make a github issue? We'll see what the neo guys say, but I think it should be ok to have comma separated sets.

或者,您可以执行多个ON CREATE:

As an alternative, you can do multiple ON CREATEs:

MERGE (n:User {email: {email}})
ON CREATE n
  SET n = {user}
ON CREATE n
  SET n.created = timestamp()
WITH n WHERE n.created = timestamp()
RETURN n

这篇关于合并查询:在创建时设置地图和"created"属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆