Why is not I able to save all properties to each node using UNWIND?

If I instead only run: CREATE (pc:Product2{catalogPathID: line.catalogPathID})

The all nodes are added with the property catalogPathID with its value.

How do I import all properties and not only catalogPathID property?

CALL apoc.load.directory("*.json", "json")
YIELD value as files
UNWIND files as file
CALL apoc.periodic.iterate('
    CALL apoc.load.json($file)
    YIELD value as line
', '
    UNWIND $line AS properties
    CREATE (n: Product2) SET n = properties
    
    //CREATE (pc:Product2{catalogPathID: line.catalogPathID}) //Process line here

', {batchSize:10000, parallel:true, params: {file: file}})
YIELD batches, total, updateStatistics
RETURN batches, total, updateStatistics

What does your json file structure look like? Are you getting an error or incorrect results? Is, what are that? Also, I don’t see a definition for $file. I believe you can access the values directly that are returned from the first query. Finally, you probably need a ‘return’ statement following the call/yield clause in the first query.

mas a note, not sure apoc.periodiciterate is the right choice. From what I read, apoc.load.json will return a single map or an array of maps. It’s will not return rows of data, which is what periodic.iterate iterates over.

When I add .partNumbers after value, then it create a node with the partNumber properties, but I do not want the properties of the partNumbers, instead I want the properties of the Product.

CALL apoc.load.directory("*.json", "json")
YIELD value as files
UNWIND files as file
CALL apoc.load.json(file) YIELD value
UNWIND value.partNumbers AS properties
CREATE(n:Product2) SET n = properties

Hi @glilienfield

I'm playing around here as I'm very new to Neo4j...

I tried this:

CALL apoc.load.directory("*.json", "json")
YIELD value as files
UNWIND files as file
CALL apoc.load.json(file) YIELD value
UNWIND value AS properties
CREATE(n:Product2) SET n = properties

Getting this:

kasipasi_0-1665258485204.png

This data is coming from the partNumber array.. I dont want to store this data for the Product, this data belongs to the Part node label that is the children on Product.

kasipasi_1-1665258581203.png

Hi @glilienfield

No error, nodes are created, but without any properties.

below is an example with two different records (productID), as you can see both have different properties, so I cannot hardcode property by property.

Every productID has then children (nodel label: Part) that I will later create nodes for and create a relationship between those children and their parent (nodel label Product) productID.

[
    {
        "Fabricant": "ecmu csr",
        "D\u00e9signation": "roulement \u00e0 rotule sur rouleaux, al\u00e9sage cylindrique",
        "R\u00e9f\u00e9rence": "22205",
        "Diam\u00e8tre d'arbre (mm)": "25",
        "Diam\u00e8tre exter (mm)": "52",
        "\u00e9paisseur (mm)": "18",
        "catalogPathID": "TRACEPARTS:TP01002001007003",
        "catalogPathName": "Spherical roller bearings",
        "productID": "90-26102021-048654",
        "productName": "22200",
        "manufacturer": "ecmu csr",
        "productURL": "https://www.traceparts.com/en/product/ecmu-csr-22200?CatalogPath=TRACEPARTS%3ATP01002001007003&Product=90-26102021-048654",
        "productImage3Dmodel": "",
        "productImagePicture": "https://cdn.tracepartsonline.net/PartsDefs/Production/CSR/90-26102021-048654/Pictures/90-26102021-048654L.gif",
        "productImageDocument": "https://cdn.tracepartsonline.net/PartsDefs/Production/CSR/90-26102021-048654/Documents/schema.jpg",
        "partNumbers": [
            {
                "Index": "1",
                "Selector": "1",
                "R\u00e9f\u00e9rence": "22205",
                "D\u00e9signation": "roulement \u00e0 rotule sur rouleaux, al\u00e9sage cylindrique",
                "Diam\u00e8tre d'arbre (mm)": "25",
                "Diam\u00e8tre exter (mm)": "52",
                "\u00e9paisseur (mm)": "18",
                "Masse": "0,26"
            },
            {
                "Index": "2",
                "Selector": "12",
                "R\u00e9f\u00e9rence": "22206",
                "D\u00e9signation": "roulement \u00e0 rotule sur rouleaux, al\u00e9sage cylindrique",
                "Diam\u00e8tre d'arbre (mm)": "30",
                "Diam\u00e8tre exter (mm)": "62",
                "\u00e9paisseur (mm)": "20",
                "Masse": "0,29"
            }
        ]
    },
    {
        "Selection": "29230-E1-MB",
        "catalogPathID": "TRACEPARTS:TP01002001007003",
        "catalogPathName": "Spherical roller bearings",
        "productID": "33-06052019-117788",
        "productName": "Axial spherical roller bearings 292..-E1, main dimensions to DIN 728/ISO 104, single direction, separable",
        "manufacturer": "Schaeffler Technologies AG & Co. KG",
        "productURL": "https://www.traceparts.com/en/product/schaeffler-technologies-ag-co-kg-axial-spherical-roller-bearings-292e1-main-dimensions-to-din-728iso-104-single-direction-separable?CatalogPath=TRACEPARTS%3ATP01002001007003&Product=33-06052019-117788",
        "productImage3Dmodel": "",
        "productImagePicture": "https://cdn.tracepartsonline.net/PartsDefs/Production/INAFAG/33-06052019-117788/Pictures/33-06052019-117788L.gif",
        "productImageDocument": "",
        "partNumbers": [
            {
                "Index": "1",
                "Selector": "1",
                "Product": "29230-E1-MB",
                "Description": "Spherical roller thrust bearings"
            },
            {
                "Index": "2",
                "Selector": "2",
                "Product": "29232-E1-MB",
                "Description": "Spherical roller thrust bearings"
            },
            {
                "Index": "3",
                "Selector": "3",
                "Product": "29234-E1-MB",
                "Description": "Spherical roller thrust bearings"
            },
            {
                "Index": "4",
                "Selector": "4",
                "Product": "29236-E1-MB",
                "Description": "Spherical roller thrust bearings"
            },
            {
                "Index": "5",
                "Selector": "5",
                "Product": "29238-E1-MB",
                "Description": "Spherical roller thrust bearings"
            },
            {
                "Index": "6",
                "Selector": "6",
                "Product": "29240-E1-MB",
                "Description": "Spherical roller thrust bearings"
            },
            {
                "Index": "7",
                "Selector": "7",
                "Product": "29244-E1-MB",
                "Description": "Spherical roller thrust bearings"
            },
            {
                "Index": "8",
                "Selector": "8",
                "Product": "29248-E1-MB",
                "Description": "Spherical roller thrust bearings"
            },
            {
                "Index": "9",
                "Selector": "9",
                "Product": "29252-E1-MB",
                "Description": "Spherical roller thrust bearings"
            },
            {
                "Index": "10",
                "Selector": "10",
                "Product": "29256-E1-MB",
                "Description": "Spherical roller thrust bearings"
            },
            {
                "Index": "11",
                "Selector": "11",
                "Product": "29260-E1-MB",
                "Description": "Spherical roller thrust bearings"
            }
        ]
    }
]

I get the url path of each json file here:

kasipasi_0-1665254874669.png

Here is code to import one json file. I removed the 'part numbers' property, as it is not a map and can not be stored as a node property. I assume the list of part numbers may be imported as part nodes and related to the product node. This can be added to the current script if that is your requirement.

CALL apoc.load.json("sample.json") yield value
unwind value as product
with apoc.map.removeKey(product, "partNumbers", {}) as map
create(n:Product)
set n = map
return n

Incorporating this in your latest multiple-file code, you can try this:

CALL apoc.load.directory("*.json", "json")
YIELD value as files
UNWIND files as file
CALL apoc.load.json(file) yield value
unwind value as product
with apoc.map.removeKey(product, "partNumbers", {}) as map
create(n:Product)
set n = map
return n

You can try this if you want to batch them in separate transactions:

:auto CALL apoc.load.directory("*.json", "json")
YIELD value as files
UNWIND files as file
CALL apoc.load.json(file) yield value
unwind value as product
call {
with product
with apoc.map.removeKey(product, "partNumbers", {}) as map
create(n:Product)
set n = map
} in transactions of 1000 rows