如何使用Python将JSON文件导入MongoDB [英] How to import JSON file to MongoDB using Python

查看:119
本文介绍了如何使用Python将JSON文件导入MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个JSON文件currencies.json:

I have this JSON file, currencies.json:

{
    "AUD": 1.5978,
    "BGN": 1.9558,
    "BRL": 4.0726,
    "CAD": 1.5868,
    "CHF": 1.1703,
    "CNY": 7.7975,
    "CZK": 25.405,
    "DKK": 7.4478,
    "GBP": 0.87285,
    "HKD": 9.6889,
    "HRK": 7.4398,
    "HUF": 312.9,
    "IDR": 16993.0,
    "ILS": 4.2984,
    "INR": 80.255,
    "ISK": 122.1,
    "JPY": 129.74,
    "KRW": 1330.3,
    "MXN": 22.88,
    "MYR": 4.8365,
    "NOK": 9.5715,
    "NZD": 1.7024,
    "PHP": 64.64,
    "PLN": 4.2262,
    "RON": 4.663,
    "RUB": 70.539,
    "SEK": 10.194,
    "SGD": 1.6216,
    "THB": 38.495,
    "TRY": 4.888,
    "USD": 1.2346,
    "ZAR": 14.52
}

Python中的此连接:

And this connection in Python:

from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client['countries_db']
collection_currency = db['currency']

我的数据库名称是countries_dbcurrency集合. 是否可以使用python将文件导入数据库?
感谢您的帮助.

My db name is countries_db with the currency collection. Is there a way to import the file to the db using python?
Thanks for your help.

推荐答案

您可以使用 查看全文

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