How to set data type mongoexport

The problem is that I found that mongoexport cannot store the datatype in the db. For example, there is a field called "tweetID", it must be a string of numbers, for example "23465478". After exporting the collection to a csv file, I found that for some entries the tweetID is exported as decimal type, for example "254323467.0", and some entries are not. To avoid unnecessary mistakes, I just want to export all fields as a clean string. Does anyone know how to set this in the mongoexport command? Thanks in advance.

+3


source to share


1 answer


You can not. If mongoexport exported 123 as 123.0, then 123 was a double type in the document. You should try to insert this value as a 32 or 64 bit integer

db.collection.insert({ "tweetId" : NumberLong(1234567) })

      

mongoexport exports JSON using strict JSON representation mode , which inserts some type information into JSON so that MongoDB JSON guerrillas (like mongoimport) can reproduce the correct BSON data types, while the exported JSON still conforms to the JSON standard



{ "tweetId" : { "$numberLong" : "1234567" } }

      

To store all the type information, use mongodump / mongorestore instead. To export all field values ​​as strings, you need to write your own script with a driver that fetches each document and plots all the values.

+4


source







All Articles