python import json into pymongo

import json
from pymongo import MongoClient

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

with open('currencies.json') as f:
    file_data = json.load(f)

# if pymongo < 3.0, use insert()
collection_currency.insert(file_data)
# if pymongo >= 3.0 use insert_one() for inserting one document
collection_currency.insert_one(file_data)
# if pymongo >= 3.0 use insert_many() for inserting many documents
collection_currency.insert_many(file_data)

client.close()

Here is what the above code is Doing:
1. We’re opening the currencies.json file and loading the data into a variable called file_data.
2. We’re using the insert() method to insert the data into the currency collection.
3. We’re using the insert_one() method to insert the data into the currency collection.
4. We’re using the insert_many() method to insert the data into the currency collection.
5. We’re closing the connection to the database.