SOBAKA
BABetter Auth
•Created by SOBAKA on 5/2/2025 in #bug-reports
findOneAndUpdate in mongodbAdapter returns inconsistent result shape
Hello, first of all I want to say that I love the framework. As the result I've have been migrating to it, but I encountered the following issue. I have also created github issue (https://github.com/better-auth/better-auth/issues/2508). There are more info in the page.
Hi, I'm encountering an inconsistency with db.collection.findOneAndUpdate() in the mongodbAdapter. For some collections, it returns the updated document as expected. However, for others—like the users collection—it returns a result object in the following shape:
{
lastErrorObject: {n:1, updatedExisting: true}
value: { //updated document }
ok: 1
}
Since the transform.transformOutput() function expects the updated document directly, this is causing a bug in my case.
To be honest, I’m not entirely sure whether this is a bug in Better Auth or a quirk of the MongoDB Node.js driver.
1 replies