Mongodb branch

Merging this now, as I need to upgrade the libraries, which I'm hoping will go some way to fixing the bugs.