I’m learning how to use Mongdb and Atlas.
I successfully created documents in my Cluster0.
Using the mongoexport command I tried to export the data to a csv file but only the field column titles get created, no data. When executing the command, it says it exported 94 records, a file is created …but the data is missing.
However, if I run the mongodump command with similar syntax, that execution states it exported 94 records, a BSON file is created and and it works as expected. I used an online converter and converted the binary to csv so I do see the data I expect, but I’d rather not have that extra step with a converter.
What am I doing wrong with the mongoexport command?
I’m using Windows 10 and a CMD window.
Here is the cmd window input/output.
C:\util\mongodb-database-tools-windows-x86_64-100.7.3\bin>mongodump --uri mongodb+srv://kurt:xxxx@cluster0.286gegr.mongodb.net/ur_sensors --collection Dissolved_DO --out bin/exptest3.bin
2023-07-18T18:25:00.587-0500 writing ur_sensors.Dissolved_DO to bin\exptest3.bin\ur_sensors\Dissolved_DO.bson
2023-07-18T18:25:00.645-0500 done dumping ur_sensors.Dissolved_DO (94 documents)
C:\util\mongodb-database-tools-windows-x86_64-100.7.3\bin>
C:\util\mongodb-database-tools-windows-x86_64-100.7.3\bin>mongoexport --uri mongodb+srv://kurt:xxxx@cluster0.286gegr.mongodb.net/ur_sensors --collection Dissolved_DO --fields Temp,DO,Date,Time,HWINFO,BatVolt,Comments --type=csv --out outtestX.csv
2023-07-18T18:25:16.310-0500 connected to: mongodb+srv://[**REDACTED**]@cluster0.286gegr.mongodb.net/ur_sensors
2023-07-18T18:25:16.451-0500 exported 94 records
Here is a copy of a few of the mongodb documents, it is just JSON data:
{"_id":{"$oid":"64b6c45d54deb6b6af3b6e46"},"date":{"$date":{"$numberLong":"1689699421390"}},"requestBody":{"Temp":"28.50","DO":"7258","HWINFO":"DO2 Sensor SolarLTE1 sw:1.0.1","BatVolt":"4366.64","Comments":"Misc info","Date":"07/17/2023","Time":"17:14"}}
{"_id":{"$oid":"64b6c463867a358dbda0e8f0"},"date":{"$date":{"$numberLong":"1689699427679"}},"requestBody":{"Temp":"29.50","DO":"7076","HWINFO":"DO2 Sensor SolarLTE1 sw:1.0.1","BatVolt":"4331.18","Comments":"Misc info","Date":"07/17/2023","Time":"17:29"}}
{"_id":{"$oid":"64b6c46ae8ccbd12e9d74fb5"},"date":{"$date":{"$numberLong":"1689699434014"}},"requestBody":{"Temp":"-127.00","DO":"4967","HWINFO":"DO2 Sensor SolarLTE1 sw:1.0.1","BatVolt":"4357.77","Comments":"Misc info","Date":"07/17/2023","Time":"17:44"}}
The resulting csv file just has one line with 6 columns: Temp DO Date Time HWINFO BatVolt Comments.
Again….what is mongoexport expecting in order to do this correctly? I kinda suspect my data is causing this, maybe the quotes but I think it is proper JSON? I’d be surprise though to think Mongo was this sensitive to data.