'Saving two documents to each other as a reference in Mongoose

I have a basic client manager using mongoose/mongo as the db. The client schema is such that one client can be anothers partner.

I am able to save both two clients, and then add clientTwo as a partner for ClientOne. However when I try to save clientOne as clientTwos partner, Mongoose/Mongo crashes.

I'm a novice so there is probably something I'm missing or don't understand about one-to-one database relationships. Any suggestions?

Relationship part of the client model:

relationship: {
    status: String,
    partner: {
        type: Schema.Types.ObjectId,
        ref: "Client"
    },
    

Saving the clients:

await clientOne.save();
await clientTwo.save();

clientOne.relationship = {partner: clientTwo, status: "Partner" };
clientTwo.relationship = {partner: clientOne, status: "Partner" };

await clientOne.save();
await clientTwo.save();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source