UPDATE (AN ALTERNATIVE SOLUTION)
Upon further exploration, I discovered that what I needed was the ability to make the method static so that it could be applied independently from the class.
Let's consider the following constructor:
export const User = class User {
constructor(
email,
password,
name,
) {
this.name = name;
this.email = email;
this.password = password;
}
async save() {
const db = getDb("messages");
const result = await db.collection("users").insertOne(this);
return {
...result.ops[0],
_id: result.ops[0]._id.toString(),
};
}
newMethod (_id) {
//Perform actions using User
}
};
When fetching the User through a CRUD operation (e.g., findOne), I receive an object back that doesn't allow me to use the newMethod defined in the constructor. It appears that the query result is read-only and does not inherit the constructor's methods. How can this issue be resolved?