Skip to content

Instantly share code, notes, and snippets.

@joelhoro
Created January 19, 2020 21:16
Show Gist options
  • Save joelhoro/da6c872e8c885a105641721fb6895ca1 to your computer and use it in GitHub Desktop.
Save joelhoro/da6c872e8c885a105641721fb6895ca1 to your computer and use it in GitHub Desktop.
Insert data in mongo collection
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