Problem with Realm Override init()

Hello,

I am in the process of migrating from Realm Cloud to MongoDB Realm and I have a problem initializing an object in Swift.
When I create a new object from an existing object it also copies the primary key _id whereas today on Realm Cloud it is regenerated and not copied from the object.

Here is my class :

class MyClass: Object {
    @objc dynamic var _id: String = ObjectId.generate().stringValue
    @objc dynamic var _partition: String = ""
    @objc dynamic var name: String = ""

    override static func primaryKey() -> String? {
        return "_id"
    }
    
    override init() {
        super.init()
        self._id = ObjectId.generate().stringValue
    }}

So now I create a new object from another like this:
var newObjectMyClass = MyClass(value: existingObjectMyClass)

then newObjectMyClass._id is equal to existingObjectMyClass._id

As I did in the class declaration, I tried initializing _id directly at the variable declaration level and also in the init () function but it doesn’t work.

Did i do something wrong ?

Thanks for your help :slight_smile: