我想要基于其他lebel/collection插入数据。我有两个lebel/collection ( unit,user ),它们之间有一个关系(Business),我想根据它们之间的关系将数据插入unit。我的密码查询如下:
MATCH (u:Units)<-[:Business]-(s:Users)
WHERE s.id = 'some-user-id'
WITH count(u) as numOfUnit
// return number of units connected with user
// if numOfUnit is smaller then 2
// insert/merge new data into Units lebel/collection
// with relation between them
MERGE ( bu:Units {name:'some-name-01', info:'some-info-01' })
WHERE numOfUnit < 2
ON CREATE SET
bu.id = '${uuid()}',
bu.created = '${moment().toISOString()}'
ON MATCH SET
bu.updated = '${moment().toISOString()}'
WITH bu as bu
MATCH ( bs:Users {id: 'some-user-id' })
MERGE (bs)-[r:Business]-(bu)
RETURN properties(bu) 在运行上面的查询后,它显示了以下错误:
{ Neo4jError: Invalid input 'H': expected 'i/I' (line 10, column 18
(offset: 377))
" ON CREATE SET"
^
at Neo4jError.Error (native)
at new Neo4jError (../../../../node_modules/neo4j-driver/lib/v1/error.js:76:132)
at newError (../../../../node_modules/neo4j-driver/lib/v1/error.js:66:10)
at Connection._handleMessage (../../../../node_modules/neo4j-driver/lib/v1/internal/connector.js:355:56)
at Dechunker.Connection._dechunker.onmessage (../../../../node_modules/neo4j-driver/lib/v1/internal/connector.js:286:12)
at Dechunker._onHeader (../../../../node_modules/neo4j-driver/lib/v1/internal/chunking.js:246:14)
at Dechunker.AWAITING_CHUNK (../../../../node_modules/neo4j-driver/lib/v1/internal/chunking.js:199:21)
at Dechunker.write (../../../../node_modules/neo4j-driver/lib/v1/internal/chunking.js:257:28)
at NodeChannel.self._ch.onmessage (../../../../node_modules/neo4j-driver/lib/v1/internal/connector.js:259:27)
at TLSSocket.<anonymous> (../../../../node_modules/neo4j-driver/lib/v1/internal/ch-node.js:308:16)
code: 'Neo.ClientError.Statement.SyntaxError',
name: 'Neo4jError' }发布于 2017-10-09 11:35:53
“关于哪里的文档”条款说:
,其中在MATCH或可选MATCH子句中向模式添加约束,或者使用子句过滤的结果。
也就是说:WHERE不能与MERGE一起使用。
正如注释中所述,您的查询应该可以将WHERE条件放在WITH子句之后,因为您可以使用WHERE过滤WITH的结果。
MATCH (u:Units)<-[:Business]-(s:Users)
WHERE s.id = 'some-user-id'
WITH count(u) as numOfUnit
WHERE numOfUnit < 2
MERGE ( bu:Units {name:'some-name-01', info:'some-info-01' })
ON CREATE SET
bu.id = '${uuid()}',
bu.created = '${moment().toISOString()}'
ON MATCH SET
bu.updated = '${moment().toISOString()}'
WITH bu as bu
MATCH ( bs:Users {id: 'some-user-id' })
MERGE (bs)-[r:Business]-(bu)
RETURN properties(bu) https://stackoverflow.com/questions/46639073
复制相似问题