Hello,
can I duplicate the following graph in neo4j? and if it is possible, then what cyphers can can me?
Have a lovely day :)
Hello,
can I duplicate the following graph in neo4j? and if it is possible, then what cyphers can can me?
Hello @verachkaverachk
If you want to duplicate this graph in another database?
You can use the Graph Data Science plugin.
First, you create the in-memory graph:
CALL gds.graph.project('graph', '*', '*')
YIELD graphName AS graph, nodeProjection, nodeCount AS nodes, relationshipProjection, relationshipCount AS rels
Then, you export the graph to a new database:
CALL gds.graph.export('graph', { dbName: 'mydatabase' })
Finally, you can create the new database and use it:
:use system
CREATE DATABASE mydatabase;
:use mydatabase
Regards,
Cobra
thank you so much for your answers
and if I want to duplicate this graph in the same databse? is it possible?
and if it is, then which query can help me?
You can have a look at APOC plugin with clone nodes functions or clone subgraph functions. I think the apoc.refactor.cloneNodesWithRelationships()
function is what you need.
Maybe this query will help you:
MATCH (n)
CALL apoc.refactor.cloneNodesWithRelationships([n])
YIELD input, output
RETURN *
Hello ,I've installed the APOC library, and tried the suggested query.
this one:
MATCH (n)
CALL apoc.refactor.cloneNodesWithRelationships([n])
YIELD input, output
RETURN *what i've tried to get was this whole graph twice , like to saparated similar graphs:
What I try to do is find a query that will duplicate my original graph and i'll gey two of these.
What query can I do to solve it?
have a great day.
Vera
Can you share your dataset please?
Where get I get it from?(the dataSet) so I can send it here?
The dataset is the data, can you share queries to recreate the graph?
I create the graph with the help of java (Springboot Dao) it starts with an entity of CellType that represents the type of a node I'm going to use(operation or input ) and with the first celltype(that must be a type of input) I connect it to a "real cell" and I call it "cellInstaces".(they also will appear in my frontend later without all the attributes). This cellInstance is going to be connected to another cellInstance from Celltype(again cellInstance must have a type-cellType) of function because in the end my purpose is to run a simulator on this graph and calculate stuff from function to function. Then, I connect an entity named a subgraphInstance to cellInstance(that represents the input)to my cellInstance. and all the nodes that are connected to this first cellInstance we will see them.
the query I use to create cell instance is this one
and if you meant they tables that represents the data of this graph for example:
You can try this query to duplicate all nodes and their relationships:
MATCH (n)
WITH collect(n) AS nodes
CALL apoc.refactor.cloneSubgraph(nodes)
YIELD input, output, error
RETURN input, output, error;
You can also add a WHERE
clause to select nodes and their relationships from of a subgraph:
MATCH (n)
WHERE n.name = "Graph1"
WITH collect(n) AS nodes
CALL apoc.refactor.cloneSubgraph(nodes)
YIELD input, output, error
RETURN input, output, error;
There is more documentation here.
I will try it and let you know today! ,thank you so so much for trying to help me understand !!
yeahi! it works!
thank you so much for helping me
Hello!
Can I duplicate my graph by his name or id with a query?for example if I have a few different subgraphs(When I say subgraphisntance i mean the node and all his connected elements) and I want to duplicate all the elements of a specific subgraph in my DB and not duplicate them all, is there a way to do it with apoc? Like you showed me with the first query but this time finding the whole subgraph by his id or name?
Vera
Hello @verachkaverachk
It's in the answer I gave you, the second query with the WHERE
clause should do what you want.
Regards,
Cobra
I tried the second one, and got only 1 duplicated node which was Graph1 that represents subGraphInstance, my problem is that i got it without all the connected elements of this node and I need them too
All the nodes of the subgraph must be tagged with the property, not only one node.
Can you please elaborate how will the second query look like if will tag the other nodes there??
Also is there a way to create a query where I can choose specific nodes from my graph and duplicate them and get their connections ?