Search code examples
mongodbmongoimport

Importing Date-datatype using mongoimport


I have many GB of data stored in PostgreSQL database and i need those to be imported into the MongoDB. I did this using CSV export and mongoimport.

There are columns like this '2011-06-25' in that CSV and it has been imported as string, not as MongoDate, so i cannot effectively search by date.

I've found this : http://www.mongodb.org/display/DOCS/Import+Export+Tools#ImportExportTools-Example%3AImportingInterestingTypes but the example says, i need to use JSON structure for the file. Do i really need to export JSON file from PostgreSQL?

If i do - how?

If i don't, how to export "MongoDate" through CSV?


Solution

  • Your options:

    • import the stuff as CSV and convert the data after the import to Date() (either using the mongo console or using a script written in your favorite language)

    • import your data as JSON and using the $date descriptor for converting date strings into Date instances