Skip to content

Commit

Permalink
fix: fix compatibility issue with MongoDB 4.X (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
rawb1 committed Oct 12, 2021
1 parent 926b421 commit 975ced7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/lovely-days-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@accounts/mongo-password': patch
'@accounts/mongo-sessions': patch
---

Fix compatibility issue with MongoDB 4.X
3 changes: 2 additions & 1 deletion packages/database-mongo-password/src/mongo-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ export class MongoServicePassword implements DatabaseInterfaceServicePassword {
user._id = this.options.idProvider();
}
const ret = await this.userCollection.insertOne(user);
return (ret.ops[0]._id as ObjectID).toString();
// keep ret.ops for compatibility with MongoDB 3.X, version 4.X uses insertedId
return ((ret.insertedId ?? ret.ops[0]._id) as ObjectID).toString();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/database-mongo-sessions/src/mongo-sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export class MongoSessions implements DatabaseInterfaceSessions {
}

const ret = await this.sessionCollection.insertOne(session);
return (ret.ops[0]._id as ObjectID).toString();
// keep ret.ops for compatibility with MongoDB 3.X, version 4.X uses insertedId
return ((ret.insertedId ?? ret.ops[0]._id) as ObjectID).toString();
}

/**
Expand Down

0 comments on commit 975ced7

Please sign in to comment.