1

I have file.csv with similar to this structure

loremipsum; machine, metal

As i understand, succeful import will looks like

{
 text: "loremipsum", << string
 tags: ["machine","metal"] << object with two fields
}

The best result i get

{
 text: "loremipsum", << string
 tags: "machine, metal" << string
}

If i understand it correctly then please tell me how to do succeful import. Thanks.

Edit: because "tags" object should contain ~16 urls, so tell me how it should be stored correctly.

asked Sep 20, 2017 at 5:59

2 Answers 2

1

Ideally, below command should be used to import csv file to mongoDb (Maybe you are using the same):

mongoimport --db users --type csv --headerline --file /filePath/fileName.csv

I think ,Your Problem is with array type of data (if I understood correctly...!!).

Then, You need to first add one document in collection and export it as CSV file. This will give you the format which is expected by above command to import your data correctly. And then Arrange your data as per exported CSV file.

link Answer Here Explained it Very well

answered Sep 20, 2017 at 6:34
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you. Also im find another easier way. Snippet code is there (3 lines of code) stackoverflow.com/a/29501257/6071087 you have to replace names and execute it, done.
1

I had this data in Excel

enter image description here

I wanted like this in MongoDB

{
"name":"John",
"age":30,
"cars":[ "Ford", "BMW", "Fiat" ]
}

I did replaced the headings like cars.0 cars.1 cars.2

Like this enter image description here

I used the tool mongoimport and ran this command

mongoimport.exe --uri "mongodb+srv:/localhost/<MYDBName>" --username dbuser --collection ----drop --type csv --useArrayIndexFields --headerline --file 1.csv

here my csv is 1.csv

answered Mar 12, 2021 at 12:46

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.