Realm Function schema problem while updating records

Goal:
Trying to update a single field for a list of object ids

All Schema: all fields are optional

Object was created with iOS SDK Client.
What an object looks like:

{
    "_partition": "...*",
    "_modifiedByDevice": null, // schema: object
    "_modifiedByUser": null, // schema: objectId
    "firstName": "test",
    "lastName": "test",
    "parentObjectId": null
}

Function running as logged in user with r/w sync access to partitions .
My Update Code in Function:

await myCollection.updateMany(
    { _id: { $in: toModifyObjectIds } },
    { $set: { parentObjectId: parentObject._id } },
    { session } // transaction session
)

Error
update not permitted for document with _id: ObjectID(“60df0741b5269f8f19fc2a78”) : could not validate document:
_modifiedByDevice: Invalid type. Expected: undefined, given: null
_modifiedByUser: Invalid type. Expected: undefined, given: null

Update:

Using { $set: { parentObjectId: parentObject._id, _modifiedByDevice: BSON.undefined, _modifiedByUser: BSON.undefined } }, changes the type in the Database from null to Undefined.
Then subsequent updates can omit setting BSON.undefined value.
But the original object was created using the iOS SDK Realm Sync, which does not make sense

Update:

Using BSON.undefined in Cloud Function update succeeded but generated with a sync error in device:

"Detailed Error: expected element at path { table: \"XXX\", fullPath: \"_modifiedByDevice\" } to be an embedded document, was primitive.Undefined instead"

iOS Class

open class MyXObject: Object {
     
    @objc dynamic public var _id: ObjectId = ObjectId.generate()
    @objc dynamic public var _partition: String = "...*"
    @objc public dynamic var _modifiedByDevice: DeviceObject? = DeviceObject()
    @objc public dynamic var _modifiedByUser: ObjectId? = nil
    @objc public dynamic var firstName: String? = nil
    @objc public dynamic var lastName: String? = nil
    @objc public dynamic var parentVetObjectId: ObjectId?

    public override static func primaryKey() -> String? { "_id" }

}

Schema JSON

{
    "collection": "MyXObject",
    "database": "Realm",
    "relationships": {},
    "schema": {
        "bsonType": "object",
        "properties": {
            "_id": {
                "bsonType": "objectId"
            },
            "_partition": {
                "bsonType": "string"
            },
            "_modifiedByDevice": {
                "bsonType": "object",
                "properties": {
                    [..Clipped..]
                },
                "required": [ "_id" ],
                "title": "DeviceObject"
            },
            "_modifiedByUser": {
                "bsonType": "objectId"
            },
            "firstName": {
                "bsonType": "string"
            },
            "lastName": {
                "bsonType": "string"
            },
            "parentVetObjectId": {
                "bsonType": "objectId"
            }
        },
        "required": [
            "_id",
            "_partition"
        ],
        "title": "MyXObject"
    }
}