gpt4 book ai didi

javascript - 通过 "MATCH (n) DETACH DELETE n"运行 "neo4j-driver"不起作用

转载 作者:行者123 更新时间:2023-12-02 22:12:29 25 4
gpt4 key购买 nike

我正在测试 neo4j-driver package通过 JavaScript/TypeScript 运行 Cypher 查询。

我可以很好地运行大多数查询,但每次我尝试运行命令 MATCH (n) DETACH DELETE n 我的程序总是挂起,什么也没有发生。

我的代码:

// main.ts

import neo4j from "neo4j-driver"

const main = async () => {
const driver = neo4j.driver("bolt://localhost:7687",
neo4j.auth.basic("neo4j", "telmo"))

const session = driver.session()

console.log("This command works fine")
await session.run(`CREATE (n:Person {name: "Bob"}) RETURN n.name`)

console.log("This one does not")
await session.run("MATCH (n) DETACH DELETE n")

console.log("The code never even gets here")

session.close()
driver.close()
}

main()

有谁知道为什么程序在 MATCH (n) DETACH DELETE n 上挂起,我该如何修复它?请注意,我的数据库仅用于测试,并且数据量非常少。

最佳答案

当您执行 match(n) detach delete n ..它会加载图中的所有关系和节点,并且您的堆大小可能不足以一次加载所有数据。尝试使用以下查询来批量执行作业,调用 apoc.periodic.iterate(
“匹配(n)返回n”,
“DETACH DELETE n”,{batchSize:10000,并行:false})

在此处了解有关 apoc.iterate 的更多信息 http://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/cypher-execution/commit-batching/

关于javascript - 通过 "MATCH (n) DETACH DELETE n"运行 "neo4j-driver"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59516993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com