Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-26-2022 05:48 AM
Hi all
The idea is simple:
Say we have this common document structure:
{
"company_number": int,
"number_of_employees": int
"company status": string
"date_of_creation": date
"date_of_cessation": date
}
But not all companies have a cessation day because they are operative...
Company 1 is still operative:
{
"company_number": 001,
"number_of_employees": 450
"company status": "OPERATIVE"
"date_of_creation": 01/02/1968
"date_of_cessation": date (It doesn't have a cessation date)
}
Company 2 is no longer operative:
{
"company_number": 002,
"number_of_employees": 500
"company status": "NO OPERATIVE"
"date_of_creation": 01/02/1970
"date_of_cessation":01/02/2022
}
I would like to know If Neo4j allows me to upload these types of JSON documents by using the Cypher query. I don't want that Cypher query fails because date_of_cessation doesn't exist in some documents.
Let me know pls!
09-26-2022 08:16 AM
There are a few approaches. Some people like to use the coalesce() function to set a default when the value is missing in the import row.
https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-coalesce
You could implement some conditional logic leveraging a 'call' subquery. The syntax is like the following. Insert this in your code for each property that you want to conditionally process that may be null. The need for the double 'with' statement is that the query parser will complain that a 'with' in a call subquery has to be simple. To get around this, a second one is added that supports the 'where' clause.
call {
with row
with row
where row.property is not null
//do something
//you can not return a value though
}
You could implement conditional logic using apoc methods. Use the do.when() or do.case() methods when the query needs to write to the database.
https://neo4j.com/labs/apoc/4.1/overview/apoc.do/
You can use do.when() when the query does not need to write.
https://neo4j.com/labs/apoc/4.4/overview/apoc/apoc.when/
All the sessions of the conference are now available online