的问题是一样的标题和CYPHER语句就像如下:如何在一个密码中将标签从一个节点复制到另一个节点?
Match (n: test) CREATE (copy : LABELS(n)) set copy = n
其目的是创建具有相同的属性和相同标签的其他节点的节点,但是它不”现在工作,因为我们不能使用像LABELS(n)
这样的表达式将节点设置为节点。
我该如何让它工作?
的问题是一样的标题和CYPHER语句就像如下:如何在一个密码中将标签从一个节点复制到另一个节点?
Match (n: test) CREATE (copy : LABELS(n)) set copy = n
其目的是创建具有相同的属性和相同标签的其他节点的节点,但是它不”现在工作,因为我们不能使用像LABELS(n)
这样的表达式将节点设置为节点。
我该如何让它工作?
不幸的是,标签目前不能直接从数据值中设置。
您可以获取要复制的节点的属性和标签,然后动态创建您执行的另一个cypher语句。
使用事务API,它看起来是这样的:
// requires cypher-rest
// npm i cypher-rest
'use strict';
const util = require('util');
const c = require('cypher-rest');
const neoUrl = 'http://127.0.0.1:7474/db/data/transaction/commit';
const copyNode = propertyObjMatch => {
return new Promise((resolve, reject) => {
// find node(s) via property matching and return it(/them)
const cypher = `MATCH (x ${util.inspect(propertyObjMatch)}) RETURN DISTINCT x, LABELS(x) AS labels`;
return c.run(cypher, neoUrl, true) // third parameter set to true to always return a list of results
.then(results => {
// iterate over results and create a copy one by one
results.forEach(result => {
const copy = `CREATE (copy:${[...result.labels].join(':')}) SET copy = ${util.inspect(result.x)} RETURN copy`;
c.run(copy, neoUrl);
});
})
});
};
// create a node
c.run('CREATE (x:LABEL1:LABEL2 {withProp: "and value", anotherProp: "test"}) RETURN x', neoUrl).then(() => {
copyNode({withProp: 'and value', anotherProp: 'test'})
.then(console.log)
});
请原谅hackiness,但它应该跨越带来的地步。