如何在不使用NumberInt(...)进行任何包装的情况下导出mongodb? [英] how to export mongodb without any wrapping with NumberInt(...)?

查看:157
本文介绍了如何在不使用NumberInt(...)进行任何包装的情况下导出mongodb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将mongodb导出为json,这是一条记录:

I want to export mongodb as json, here is a record:

{"_id":{"$oid":"554f042c0e81bf483e4a4e2f"}, "batch":"3","bz":NumberInt(1)}

问题是当我使用json加载它时:

the problems is when I use json to loads it:

json.loads('{"_id":{"$oid":"554f042c0e81bf483e4a4e2f"}, "batch":"3","bz":NumberInt(1)}')

它返回ValueError: No JSON object could be decoded.这是因为json无法处理NumberInt(1).

it returns ValueError: No JSON object could be decoded. This is because json can not deal with NumberInt(1).

那么导出时如何将NumberInt(1)转换为1?

So how can I translate NumberInt(1) to 1 when I export?

推荐答案

[更新]如果您的mongo集合不包含NumberInt,并且mongoexport创建了一个包含NumberInt的json文档,则这是一个错误. 万一有人遇到与我相同的问题,我会留下答案.

[UPDATE] IF your mongo collection does not include NumberInt, and mongoexport creates a json document that includes NumberInt, this is a bug. I leave my answer in case anyone has the same issue as I had.

似乎确实是一个错误

https://jira.mongodb.org/browse/TOOLS-741 重复的 https://jira.mongodb.org/browse/TOOLS-681 已在3.1.4中修复

https://jira.mongodb.org/browse/TOOLS-741 that duplicates https://jira.mongodb.org/browse/TOOLS-681 that was fixed in 3.1.4

我使用3.1.6(最新的开发版本)进行了测试,并且可以正常工作

I tested with 3.1.6 (last dev release) and it works

这篇关于如何在不使用NumberInt(...)进行任何包装的情况下导出mongodb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆