Mongoimport csv files with string _id and upsert

后端 未结 5 2025
清歌不尽
清歌不尽 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条回答
  •  旧时难觅i
    2021-01-13 06:03

    I was able to prefix the numeric string and that worked for me. Example:

    00012345 was imported as 12345 (Type Int) string00012345 was imported as string00012345 (Type String)

    My source was a SQL database so I just did

    select 'string'+column as name
    

    Of course, you also need to do a bit of post-processing to parse the string, but far less effort than converting a rather large tsv file to json.

    I also added +1 to the jira link above for the enhancement.

提交回复
热议问题