Node.js 为什么Node-Neo4j没有正确设置数据?
想象这样一个查询:Node.js 为什么Node-Neo4j没有正确设置数据?,node.js,neo4j,cypher,node-neo4j,Node.js,Neo4j,Cypher,Node Neo4j,想象这样一个查询: match (i:QuestionOrder) set i.count=i.count+1 merge (q:Question {text: '+text here+', index: i.count}) return q 如果集合发生在同一事务中(由node-Neo4j中的同一查询暗示),则Neo4j保证写锁。但是,我得到了以下输出: [ { "columns":["q"], "data":[{"text":"Have Kids...","ind
match (i:QuestionOrder)
set i.count=i.count+1
merge (q:Question {text: '+text here+', index: i.count})
return q
如果集合发生在同一事务中(由node-Neo4j中的同一查询暗示),则Neo4j保证写锁。但是,我得到了以下输出:
[
{
"columns":["q"],
"data":[{"text":"Have Kids...","index":1,"_id":542}]
},
{
"columns":["q"],
"data":[{"text":"You are...","index":1,"_id":545}]
}
]
根据我的理解,锁应该防止
索引
相同。我是不是遗漏了什么?如何解决此问题?更改此查询以添加其他测试可能有助于并行工作。如果您有两个并发事务,则会在set操作中获取锁。因此,两者都已经读取了i.count,并使用相同的值等待
所以要么你早点抓住锁:
match (i:QuestionOrder)
set i.lock = NOT i.lock
set i.count=i.count+1
merge (q:Question {text: '+text here+', index: i.count})
return q
或者添加一个额外的检查以避免发生合并(然后必须重试)
或者在同一个tx中发送两条不同的语句,第一条语句执行锁定。addtl info-->它似乎在neo4j web客户端中工作,而不是在node-neo4j中
match (i:QuestionOrder)
WITH i, i.count + 1 as new_count
set i.count = new_count
WITH i, new_count
WHERE i.count = new_count
merge (q:Question {text: '+text here+', index: i.count})
return q