cancel
Showing results for 
Search instead for 
Did you mean: 

Any Cypher experts ? trying to create relationships for 2 cvs imports from mongo

john_allen
Node Link

guys.. since mongo-connect no showing my db as graph.. we are importing the cvs from mongo atlas exports... so yes we have the relationships as List arrays in Morphia and can see them below.. CategorizedBy is a relationship 1 of 2. 'ExhibitedIn' is the other direction.. see the object ids.

Having a hard time writing the CYPHER to create the relationship as objectids in the Array list.. see below cvs .. how do we 'split' and read the objects so our MERGE produces the CategorizedBy relationship in our neo4j graph db ?

Thanks guys a million if any help on this one.. Its a split on something not sure what ',' but the format ? so it reads each of the 5 objects in the CSV and MERGEs with the dataholontypeproperty ?

my attempt is (which failed and no idea how to attack it)

LOAD CSV WITH HEADERS FROM 'file:///dataholontypes.csv' AS row
WITH row._id AS _id, row.categorizedBy AS categorizedby
MATCH (dhtp:Dataholontypeproperty {_id: categorizedby})
MERGE (dhtp)-[relcatby:CATEGORIZEDBY {}]->(dhtp)
RETURN count(relcatby)

below is the CSV row examples and the CYPHER I used to load each file - which was fine and good.. that was the easy bit.. the above is more tricky.

The other relationship to define in the graph is 'exhibitedIn' below in propertytypes.. where you can see the parent objectid of the dataholon type

LOAD CSV WITH HEADERS FROM 'file:///dataholontypes.csv' AS row
RETURN row
LIMIT 15

{
"_t": "DataHolonType",
"name": "Geospatial",
"categorizedBy": "[{"$oid":"5f77a308e74f033e954fa447"},{"$oid":"5f77a308e74f033e954fa448"},{"$oid":"5f77a308e74f033e954fa449"},{"$oid":"5f77a308e74f033e954fa44a"},{"$oid":"5f77a308e74f033e954fa44b"}]",
"issourcedFrom": "[{"$oid":"5f77a307e74f033e954fa442"},{"$oid":"5f77a308e74f033e954fa443"}]",
"description": "Land surface mappings",
"classifies": "[{"$oid":"5f77a307e74f033e954fa440"}]",
"_id": "5f77a307e74f033e954fa441"
}

LOAD CSV WITH HEADERS FROM 'file:///dataholontypes.csv' AS row
WITH row.name AS name, row.description AS description, row._id AS _id RETURN _id, name, description
LIMIT 20

CREATE CONSTRAINT ON (dht:Dataholontype) ASSERT dht.id IS UNIQUE;

LOAD CSV WITH HEADERS FROM 'file:///dataholontypes.csv' AS row
WITH row.name AS name, row.description AS description, row._id AS _id
MERGE (dht:Dataholontype {_id:_id})
SET dht.name = name, dht.description = description
RETURN count(dht)

{
"inactive": "false",
"_t": "DataHolonTypeProperty",
"classifiesTo": "[{"$oid":"5f77a309e74f033e954fa44c"},{"$oid":"5f77a309e74f033e954fa44d"},{"$oid":"5f77a309e74f033e954fa44e"},{"$oid":"5f77a309e74f033e954fa44f"},{"$oid":"5f77a309e74f033e954fa450"},{"$oid":"5f77a309e74f033e954fa451"},{"$oid":"5f77a309e74f033e954fa452"}]",
"name": "Scope-Scale",
"description": "Categories, levels, etc ..",
"_id": "5f77a308e74f033e954fa447",
"exhibitedIn": "[{"$oid":"5f77a307e74f033e954fa441"}]"
}

CREATE CONSTRAINT ON (dhtp:Dataholontypeproperty) ASSERT dhtp.id IS UNIQUE;

LOAD CSV WITH HEADERS FROM 'file:///dataholontypeproperties.csv' AS row
WITH row.inactive AS inactive, row.name AS name, row.description AS description, row._id AS _id
MERGE (dhtp:Dataholontypeproperty {_id:_id})
SET dhtp.inactive, dhtp.name = name, dhtp.description = description
RETURN count(dhtp)

2 REPLIES 2

Joel
Ninja
Ninja

Do you have a sketch of the desired data model (or even subset for this merge), showing node labels, and relationship types?

Just to confirm, you have loaded the nodes already and are now loading the relationships?

*** I'm immediately curious about this relationship

Start and end node are the same, this is intentional?

dominicvivek06
Graph Fellow

Hi @john.allen, did you try mongodb apoc libaries ?