Adding a backend for MongoDB

I fixed up a few bugs and adding testing. 

See #1 for the original PR.