Insert each row in excel as a separate document in Mongodb collection

Requirement - Excel has 164 rows. I want each record in Excel to be inserted as a separate document in the MongoDB collection. However, the records are getting inserted as an array in the same document collection

Here is the JSON Input rawdata.json

{“data”:[{“SKU”:“SKU1234”,“Desc”:“Ganesh”,"Name ":“Name Desc”,“Test”:“Test fast”,“Test 2”:“Test Test 2”,“Test 3”:“Test Test 3”},{“SKU”:“SKU2345”,“Desc”:“John”,"Name ":“Mark”,“Test”:“Test fast”,“Test 2”:“Test Test 2”,“Test 3”:“Test Test 3”},{“SKU”:“SKU3456”,“Desc”:“Ganesh”,"Name ":“Thomas”,“Test”:“Test 2”,“Test 2”:“Test Test 2”,“Test 3”:“Test Test 3”}]}

Please share your workflow

Share the output returned by the last node

MongoDB Collection 1:
{
“_id”: {
“$oid”: “642f8acb9fc758951597c977”
},

"SKU": "SKU1234",
"Desc": "Ganesh",
"Name ": "Name Desc",
"Test": "Test fast",
"Test 2": "Test Test 2",
"Test 3": "Test Test 3"

}

MongoDB Collection 2:
{
“_id”: {
“$oid”: “642f8acb9fc75895159776977”
},

"SKU": "SKU2345",
"Desc": "John",
"Name ": "Mark",
"Test": "Test fast",
"Test 2": "Test Test 2",
"Test 3": "Test Test 3"

}

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Siva_Manickam,

Have you tried using the Item Lists node between the Move Binary Data and MongoDB node and splitting on the data field? I suspect that will do what you are after, Example below.

I’m receiving an error “ERROR: The provided field ‘data’ is not an array”

Please help to resolve this issue.

Thanks,
Siva Manickam

Hey @Siva_Manickam,

I missed that you might need to first data to a json object in a set node as well. Add a set node before item lists and set data to be {{ JSON.parse($json.data) }} then in item lists set the option to data.data and that should sort it, if it doesn’t a code node might be needed.

I was able to resolve this issue with the function code node. Please close this issue.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.