【问题标题】:MongoDB Compass Exporting Collection with Unwanted MetadataMongoDB Compass 导出带有不需要的元数据的集合
【发布时间】:2019-10-25 04:54:46
【问题描述】:

使用 MongoDB Compass(无论查询如何)将集合导出到 JSON 时,输出现在包括元数据($oid、$numberInt、$numberDouble)。在过去的几周里,我已经导出了几个集合,但现在每个导出都包含元数据,这会影响 JSON 在外部软件中的解析方式。

我已经尝试更新到最新版本的 MongoDB (4.0.10) 和 MongoDB Compass (1.18.0) 社区版,但没有解决方案。

预期输出:{"_id":"unique_id"},"transaction_id":"1059833"},"transaction_amount":"2000"}}

实际输出:{"_id":{"$oid":"unique_id"},"transaction_id":{"$numberInt":"1059833"},"transaction_amount":{"$numberInt":"2000" }}

【问题讨论】:

  • 实际输出正确吗?你错过了一个结束}你能给我们一个数据库中的数据样本吗请editing你的问题
  • 实际输出数据不正确。键值对应该是 {transaction_id: 1059833} 但由于某种原因,导出会将键分配给具有自己的键值对的对象。

标签: json mongodb mongodb-query mongodb-compass


【解决方案1】:

如果您使用的是 mongo-java-driver,请尝试以下代码:

Use new JsonWriterSettings(JsonMode.SHELL).

Document doc = new Document("startDate", new Document("$gt", first).append("$lt", second)); 
System.out.println(doc.toJson(new JsonWriterSettings(JsonMode.SHELL))); 

页面上的更多详细信息: https://mongodb.github.io/mongo-java-driver/3.7/bson/extended-json/

【讨论】:

    猜你喜欢
    • 2021-07-23
    • 1970-01-01
    • 2019-01-22
    • 2019-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    相关资源
    最近更新 更多