gpt4 book ai didi

javascript - 如何通过使用属性(n)的密码请求获取 Node ID?

转载 作者:行者123 更新时间:2023-12-01 02:48:00 24 4
gpt4 key购买 nike

我正在尝试获取 SomeNode 和 OtherNodes 的所有属性和 ID。

我有这个查询:

const neo = driver.session();
const responseObj = { error: false, message: 'success: getting nodes' };

const q = 'MATCH (n:SomeNode)-[:has]->(o:OtherNode), ' +
' RETURN properties(n) AS node, properties(o) AS otherNode';

neo.run(q)
.then((result) => {
const records = result.records;
const nodes = [];

records.forEach((record) => {
nodes.push({
node: record.get('node'),
other: record.get('otherNode')
});
});

responseObj.nodes = nodes;
neo.close();
respond(null, responseObj);
});
正如预期的那样,这给了我一个包含 SomeNode 属性和 OtherNode 属性的对象数组,但我还需要 SomeNode 和 OtherNode 的 id。实现这一目标的最佳方法是什么?

如果返回 Node 如何获取ID?

enter image description here

最佳答案

您可以使用map projection获取 Node 的属性并进行自定义,例如通过添加额外的 map 属性。

MATCH (n:SomeNode)-[:has]->(o:OtherNode)
RETURN n {.*, _id:id(n)} AS node, o {.*, _id:id(o)} AS otherNode

虽然直接返回 no 应该默认包含 id。

关于javascript - 如何通过使用属性(n)的密码请求获取 Node ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47134299/

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