【发布时间】:2017-05-15 15:13:53
【问题描述】:
假设我们有我们的 MongoDB,我们想将数据备份到 .json 文件中
输出文件示例:database.json 和内部:
{
"collections": [
{"name": "admin"},
{"name": "class"},
{"name": "lesson"},
{"name": "message"},
{"name": "room"},
{"name": "student"},
{"name": "subject"},
{"name": "teacher"}
],
"subjects": [
{
"name": "Null",
"color": "#FFFFFF"
},
{
"name": "Design Art",
"color": "#82B9D6"
},
{
"name": "Plastic Art",
"color": "#a3db05"
},
{
"name": "Media And Production",
"color": "#522a64"
}, //...there is a continue to this file ....
}
每个集合都应该添加到 collections 中,并且每个集合都应该有一个包含所有信息的数组(如上所示)
我正在使用带有 pymongo 驱动程序的 python 3.4。
从数据库获取所有信息、创建 JSON 对象并将其插入到 new .json 文件
【问题讨论】:
标签: json mongodb python-3.x pymongo