Consider
in this light: Valid arguments and return values . This strongly suggests that at least one of your dictionary entries (or nested entries) is a value of a different type.
In fact, the error message tells you the type: bson.objectid.ObjectId
. You’ll need to convert this kind of value into something that a server function can return.