Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
copying nodes with labels and properties - hacky
// requires cypher-rest
// npm i cypher-rest
// gist for
'use strict';
const util = require('util');
const c = require('cypher-rest');
const neoUrl = '';
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, 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`;, neoUrl);
// create a node'CREATE (x:LABEL1:LABEL2 {withProp: "and value", anotherProp: "test"}) RETURN x', neoUrl).then(() => {
copyNode({withProp: 'and value', anotherProp: 'test'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment