Answers for "pymongo load a json file into mongodb database"

2

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()
Posted by: Guest on November-27-2020
0

how to export mongodb database to json

sudo mongoexport --db newdb -c restaurants --out newdbexport.json
Posted by: Guest on August-09-2020

Code answers related to "pymongo load a json file into mongodb database"

Python Answers by Framework

Browse Popular Code Answers by Language