More unittests. Improved mgdb query.