【问题标题】:Solution to Mongodb compass interior hyphen error?解决Mongodb罗盘内部连字符错误?
【发布时间】:2023-02-15 08:54:52
【问题描述】:

我正在尝试使用 mongodb compass 将一个大的 CSV 文件导入到 mongodb 中。数据最初通过 GDELT 来自 BigQuery,然后被转储到 40+csv 文件中。 超过一半的文件无法导入,因为它们部分通过,然后就停止了。 Compass 停止并显示错误“Interior hyphen”。似乎没有关于为什么或可能是什么的文档。

在导入时,有几个 csv 列指定为数字,但其他所有内容都被视为字符串,并在 CSV 中指定为字符串。

当表名使用连字符时,记录了 mongodb 问题的错误,这里不是这种情况。有没有人遇到过这个问题并解决了?

【问题讨论】:

    标签: mongodb csv google-bigquery mongodb-compass gdelt


    【解决方案1】:

    所以虽然我一直没能找到答案。如果需要,有一个解决方法。出于某种原因,当您通过 pymongo 从数据帧导入这些文件时,该管道似乎没有任何错误。 基本上,在需要的地方获取数据的工作是这样的:

    path = "/home/linux/Downloads/csvs2import"
    dir_list = os.listdir(path)
    
    
    dtypes = {'CountryCode': str, 
              'date': str,  
              'SQLDATE': str, 
              'ActionGeo_ADM1Code': str, 
              'lat': np.float64, 
              'long': np.float64,
              'URL': str, 
              'sentiment': np.float64, 
              'GoldsteinScale': np.float64, 
              'EventCode': str, 
              'EventBaseCode': str,
              'EventRootCode': str, 
              'QuadClass': str, 
              'Actor1Code': str, 
              'Actor1Name': str,
              'Actor1EthnicCode': str, 
              'Actor1Religion1Code': str, 
              'Actor1Religion2Code': str,
              'Actor1Geo_Fullname': str, 
              'Actor1Type1Code': str, 
              'Actor2Code': str, 
              'Actor2Name': str,
              'Actor2EthnicCode': str, 
              'Actor2Religion1Code': str, 
              'Actor2Religion2Code': str,
              'Actor2Geo_Fullname': str, 
              'Actor2Type1Code': str, 
              'NumSources': np.int32}
    
    for f in dir_list:
        print(f)
        fp = path + '/' + f
        data = pd.read_csv(fp, header=0, dtype=dtypes)
        collection.insert_many(data.to_dict('records'))
        del data
    

    这指定了位于单个文件夹(失败的文件夹)中的 csvs,然后指定了数据类型,没有数据类型它会抛出错误,因为事件代码之类的东西是分类变量,是不明确的;所以我将它们作为字符串导入(例如,050 是一个代码,因此它被导入为“050”而不是 50)。

    【讨论】:

      【解决方案2】:

      您必须确保您在导入时是selecting the proper数据类型。在 Mongo 中,同时存在时间戳和 BSON 原生日期类型。 Timestamp 类型是一个 64 位值,主要用于内部目的。 Date 类型更常用。如果在导入日期类型的时间戳时选择时间戳选项,将返回错误interior hyphen

      mongodb compass field options

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-12
        • 2014-05-14
        • 2011-09-03
        相关资源
        最近更新 更多