-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransporter.py
28 lines (22 loc) · 931 Bytes
/
transporter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""The Transporter
Reads in data from json and stores it into a mongodb instance."""
import json
from pymongo import MongoClient
# Load file for parsing.
def loadJSON(file_name):
with open(file_name) as fd:
jsonDoc = json.load(fd)
return jsonDoc
documents = loadJSON("buckets_sorted.json")
# Get a connection to mongod.
with MongoClient() as client:
# Lazy create a database in mongo called 'brovine-testdb'.
db = client['brovine-testdb']
for i in range(10):
# Create a collection (aka. table) in the brovine db called 'genes'.
for index, genebucket in enumerate(documents):
# print "Inserting %s into 'genes' collection." % genebucket['geneid']
# print index, i
genebucket["_id"] = index + i * 1000
# PyMongo does lazy collection creation, so genes collection is created on first insert.
db.genes.insert(genebucket)