Skip to content

Commit

Permalink
Bugfix on Mongo.createUser and Mongo.createSession on 4.X (#1251)
Browse files Browse the repository at this point in the history
* insertedId bugfix

* Removed commented out line

* added changeset

* Delete yarn.lock

* Update package.json; removed dependency to changeset
  • Loading branch information
awatson1978 authored Jul 24, 2023
1 parent ff983b8 commit 3f1c494
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/purple-dryers-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@accounts/mongo-password': minor
'@accounts/mongo-sessions': minor
---

MongoDB 4.X support for Meteor@2.5.1 - Mongo.createUser and Mongo.createSession bugfixes
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,8 +149,9 @@ export class MongoServicePassword implements DatabaseInterfaceServicePassword {
user._id = this.options.idProvider();
}
const ret = await this.userCollection.insertOne(user);

// keep ret.ops for compatibility with MongoDB 3.X, version 4.X uses insertedId
return ((ret.insertedId ?? ret.ops[0]._id) as ObjectID).toString();
return ((ret.insertedId ? 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 @@ -124,7 +124,8 @@ export class MongoSessions implements DatabaseInterfaceSessions {

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

}

/**
Expand Down

0 comments on commit 3f1c494

Please sign in to comment.