Store Email in MongoDB

16 Nov

I want to store all the information about an architectural project in a database. I have all the building information in mongoDB but I also want other information – like change orders or all the emails about the project. In this post, I will load my email from Outlook in to MongoDB.

In Outlook, you can export a folder to Excel. Go to File>Import and Export

Select A FILE, then choose Excel. Lastly, select the folder where you have placed all your project emails.

You should now have an Excel sheet with email information. I am only interested in the Subject, Body, and who it is from. Using Python, Pymongo, and XLRD, I converted the Excel to MongoDB:

from pymongo import Connection
from xlrd import open_workbook

wb=open_workbook(‘mailxls.xls’)
sheet=wb.sheet_by_index(0)

db=connection=Connection().building

for rownum in range(sheet.nrows):
subject=sheet.cell(rownum,0).value
body=sheet.cell(rownum,1).value
fromname=sheet.cell(rownum,2).value
db.building.email.insert({“subject”:subject,”body”:body,”from”:fromname})

db.building.email.remove({“body”:”Body”})

 

Because rownum starts at 0 and 0 is my headers, I use the last line to remove the headers. You could probably delete them out of the Excel file, or adjust your loop when you read the file. This was a quick solution since I accidentally put them in already.

Now you have emails in MongoDB and can query away. This is a good start to a project management system using mongoDB. Wondering what the value of a BIM in mongoDB would be. Do we need to maintain the relation nature of the model, or can a document model work?

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: