I am trying to use mongoimport to recreate data with string values in _id. Since identifiers look like integers (even if they are enclosed in quotation marks), mongoimport treats them as integers and creates new entries instead of re-creating existing entries.
The command that I run:
mongoimport --host localhost --db database --collection my_collection --type csv --file mydata.csv --headerline --upsert
Sample data in mydata.csv file:
{ "_id" : "0364", someField: "value" }
The result will be for mongo to insert such a record: { "_id" : 364, someField: "value" }instead of updating the record with _id "0364".
Does anyone know how to make it treat _idas strings?
Things that don't work:
- Surrounding data with double double quotes "0364" ", double and single quotes" 0364 "or" 0364 "'
- Adding an empty string to a value:
{ "_id" : "0364" + "", someField: "value" }
source
share