2016-02-04 53 views

回答

1

不幸的是,标签目前不能直接从数据值中设置。

0

您可以获取要复制的节点的属性和标签,然后动态创建您执行的另一个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,但它应该跨越带来的地步。

相关问题