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 integers and creates new records instead of upserting the existing records.
Command I'm running:
mongoimport --host localhost --db database --collection my_collection --type csv --file mydata.csv --headerline --upsert
Example data in mydata.csv:
{ "_id" : "0364", someField: "value" }
The result would be for mongo to insert a record like this: { "_id" : 364, someField: "value" }
instead of updating the record with _id "0364"
.
Does anyone know how to make it treat the _id
as strings?
Things that don't work:
- Surrounding the data with double double quotes ""0364"", double and single quotes "'0364'" or '"0364"'
- Appending empty string to value:
{ "_id" : "0364" + "", someField: "value" }