Mongoimport csv files with string _id and upsert

后端 未结 5 1995
清歌不尽
清歌不尽 2021-01-13 05:26

I\'m trying to use mongoimport to upsert data with string values in _id. Since the ids look like integers (even though they\'re in quotes), mongoimport treats them as intege

5条回答
  •  一整个雨季
    2021-01-13 06:12

    I encountered the same issue.

    I feel the simplest way is to convert the CSV file to a JSON file using an online tool and then import.

    This is the tool I used:

    http://www.convertcsv.com/csv-to-json.htm

    It lets you wrap the integer values of your CSV file in double quotes for your JSON file.

    If you have trouble importing this JSON file and encountering an error, just add --jsonArray to your import command. It will work for sure.

    mongoimport --host localhost --db mydb -c mycollection --type json --jsonArray --file 
    

提交回复
热议问题