使用mongoimport导入Date-datatype [英] Importing Date-datatype using mongoimport
问题描述
我在PostgreSQL数据库中存储了许多GB的数据,我需要将这些数据导入到MongoDB中.我使用CSV导出和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.
在CSV中有像"2011-06-25"这样的列,它已作为字符串而不是作为MongoDate导入,因此我无法按日期有效地搜索.
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.
我找到了: http://www.mongodb.org /display/DOCS/Import + Export + Tools#ImportExportTools-Example%3AImportingInterestingTypes 但是该示例说,我需要对该文件使用JSON结构.我真的需要从PostgreSQL导出JSON文件吗?
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?
如果我愿意-怎么做?
如果没有,如何通过CSV导出"MongoDate"?
推荐答案
您的选项:
-
以CSV格式导入内容,并在导入后将数据转换为Date()(使用mongo控制台或使用您喜欢的语言编写的脚本)
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)
将数据导入为JSON并使用$ date描述符将日期字符串转换为Date实例
import your data as JSON and using the $date descriptor for converting date strings into Date instances
这篇关于使用mongoimport导入Date-datatype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!