Skip to content

Commit

Permalink
mongodb version
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyrulez committed May 18, 2012
1 parent c287686 commit 517c069
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions python_code/mailboxes__load_json_mbox.py
Expand Up @@ -2,16 +2,23 @@

import sys
import os
import couchdb
import pymongo
from pymongo import Connection

try:
import jsonlib2 as json
except ImportError:
import json

JSON_MBOX = sys.argv[1] # i.e. enron.mbox.json
DB = os.path.basename(JSON_MBOX).split('.')[0]
DB_NAME = os.path.basename(JSON_MBOX).split('.')[0]

connection = Connection('localhost', 27017)
db = connection[DB_NAME]

server = couchdb.Server('http://localhost:5984')
db = server.create(DB)
docs = json.loads(open(JSON_MBOX).read())
db.update(docs, all_or_nothing=True)

collection = db['messages']
for doc in docs:
print str(doc)
collection.insert(doc)

0 comments on commit 517c069

Please sign in to comment.