"FieldPath cannot be constructed with empty string". Facing this error. Upgraded mongo version from 4.2 to 5.0.4. is it due to the upgrade?

“FieldPath cannot be constructed with empty string”. Facing this error. The code was running properly. But upgraded the mongo version from 4.2 to 5.0.4. is it due to the upgrade? Has any function used in 4.2 removed /changed in higher versions? The code is failing when it is trying to taking json data and converting it into CSV file.
I’m using python script and error came as pymongo error

Further to this, it has been identified that the mongo cursor is inside a function which takes in values for field_name to be projected.

Cursor = db.coll_name.find({}, {field_name:1})

But there are instance where no projection is required and therefore field_name becomes empty string.

This has not caused problem when the version was 4.2.23
But now version is 5.0.4

Wanted to know is this occuring as a part of this upgrade.

Looks like this extra validation on field paths in projections was added in MongoDB 4.4. https://jira.mongodb.org/browse/SERVER-43613 was opened to request that the server return a more helpful error message. Please follow that ticket for updates.

As for how to workaround this issue, if the field_name is empty you can set the entire projection to be empty or None:

if field_name:
    projection = {field_name: 1}
    projection = None
cursor = db.coll_name.find({}, projection=projection)