Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Import NASDAQ companies data into Mongo or Cosmos DB
import pymongo
from pymongo import MongoClient
import urllib2
import csv
# Are we using development or Production ?
# uri = "mongodb://"
uri = 'mongodb://localhost:27017'
# Connect to the instance and get a handle
client = MongoClient(uri)
db = client.fluid
companies = db.companies
# Let's pull the NASDAQ data directly
url = ''
csvfile = urllib2.urlopen(url)
# Read the CSV into a dict so we can pipe it into DB
reader = csv.DictReader(csvfile, delimiter=',')
# And import - I'm not too worried about batching these as it's only a few thousand entries
for line in reader:
print("Inserting " + line['Name'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment