Skip to content

Commit 3f1c494

Browse files
authored
Bugfix on Mongo.createUser and Mongo.createSession on 4.X (#1251)
* insertedId bugfix * Removed commented out line * added changeset * Delete yarn.lock * Update package.json; removed dependency to changeset
1 parent ff983b8 commit 3f1c494

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

.changeset/purple-dryers-peel.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@accounts/mongo-password': minor
3+
'@accounts/mongo-sessions': minor
4+
---
5+
6+
MongoDB 4.X support for [email protected] - Mongo.createUser and Mongo.createSession bugfixes

packages/database-mongo-password/src/mongo-password.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ export class MongoServicePassword implements DatabaseInterfaceServicePassword {
149149
user._id = this.options.idProvider();
150150
}
151151
const ret = await this.userCollection.insertOne(user);
152+
152153
// keep ret.ops for compatibility with MongoDB 3.X, version 4.X uses insertedId
153-
return ((ret.insertedId ?? ret.ops[0]._id) as ObjectID).toString();
154+
return ((ret.insertedId ? ret.insertedId : ret.ops[0]._id) as ObjectID).toString();
154155
}
155156

156157
/**

packages/database-mongo-sessions/src/mongo-sessions.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export class MongoSessions implements DatabaseInterfaceSessions {
124124

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

130131
/**

0 commit comments

Comments
 (0)