Closed sdalexandre closed 2 years ago
The problem here is that the library does not yet transform the extra update operation passed to context.updateOne(). It is something that I've been planning to add, but now for this case you can simply assign a User instance to the owner field and call updateOne without any extra parameter
dbsub.owner = new User(userId);
let result = await this.dbContext.updateOne(dbsub);
Assignment marks the field as "dirty" so will result in the following update op:
{
$set: { owner: ObjectId(...) }
}
I will update this issue once I implement the extra ops transformation.
This has been fixed in commit 768f94a736298caf5fdd641b86d08e6e13dcbce4 It will be updated on NPM shortly.
In the model of a specific class I have this:
At the insertion I can set this member and it will get something like this:
owner: ObjectId("612fe89ad0e6bf73608c6504")
But if I set it during an update with the following code:
I get something like this:
And any subsequent query to the collection where the "owner" is set like this I'am getting then the following error:
The workaround for now is using a NativeId() instead. But it can't be used directly because of the type validation don't allow this:
Instead, I'm forced to do it using an "any" type like this: