Ensure embedded hashes get the correct type
Adding in to_bson for code with scope