Improve Database deserialization

Improves the deserialization of BSON and JSON data from the database.