Created
January 19, 2020 21:16
-
-
Save joelhoro/da6c872e8c885a105641721fb6895ca1 to your computer and use it in GitHub Desktop.
Insert data in mongo collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pymongo import MongoClient | |
client = MongoClient() | |
db = client['joel'] | |
data = [ | |
{'name': 'Joel', 'country': 'Belgium'}, | |
{'name': 'Arnaud', 'country': 'Belgium'}, | |
{'name': 'Robert', 'country': 'France'}, | |
] | |
coll_name = 'test' | |
for row in data: | |
db[coll_name].insert_one(row) | |
# or db.test.insert_one(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment