MongoDB collections dont have a schema, but if you want to read it as spark dataframe all rows must have the same schema. So fieldA cant be a String and a json object at the same time. If it not present you shouldnt create an empty string, just drop the field or use null