Skip to content

Commit

Permalink
fix: move writeConcern option away from top-level to remove deprecati…
Browse files Browse the repository at this point in the history
…on warning #422 (#424)
  • Loading branch information
mingchuno authored Jun 15, 2021
1 parent 03962f4 commit cceec18
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Move `writeConcern` away from top-level option to fix deprecation warning [#422](https://github.com/jdesboeufs/connect-mongo/issues/422)

## [4.4.1] - 2021-03-23

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/express": "^4.17.9",
"@types/express-session": "^1.17.3",
"@types/mongodb": "^3.6.3",
"@types/mongodb": "^3.6.18",
"@types/node": "^14.14.20",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^4.12.0",
Expand Down
22 changes: 13 additions & 9 deletions src/lib/MongoStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type ConnectMongoOptions = {
// FIXME: remove those any
serialize?: (a: any) => any
unserialize?: (a: any) => any
writeOperationOptions?: CommonOptions
writeOperationOptions?: CommonOptions['writeConcern']
transformId?: (a: any) => any
crypto?: CryptoOptions
}
Expand All @@ -61,7 +61,7 @@ type ConcretConnectMongoOptions = {
// FIXME: remove those any
serialize?: (a: any) => any
unserialize?: (a: any) => any
writeOperationOptions?: CommonOptions
writeOperationOptions?: CommonOptions['writeConcern']
transformId?: (a: any) => any
// FIXME: remove above any
crypto: ConcretCryptoOptions
Expand Down Expand Up @@ -225,17 +225,21 @@ export default class MongoStore extends session.Store {
debug('Creating MongoDB TTL index')
collection.createIndex(
{ expires: 1 },
{ expireAfterSeconds: 0, ...this.options.writeOperationOptions }
{
expireAfterSeconds: 0,
writeConcern: this.options.writeOperationOptions,
}
)
break
case 'interval':
debug('create Timer to remove expired sessions')
this.timer = setInterval(
() =>
collection.deleteMany(removeQuery(), {
...this.options.writeOperationOptions,
w: 0,
j: false,
writeConcern: {
w: 0,
j: false,
},
}),
this.options.autoRemoveInterval * 1000 * 60
)
Expand Down Expand Up @@ -382,7 +386,7 @@ export default class MongoStore extends session.Store {
{ $set: s },
{
upsert: true,
...this.options.writeOperationOptions,
writeConcern: this.options.writeOperationOptions,
}
)
if (rawResp.upsertedCount > 0) {
Expand Down Expand Up @@ -438,7 +442,7 @@ export default class MongoStore extends session.Store {
const rawResp = await collection.updateOne(
{ _id: this.computeStorageId(sid) },
{ $set: updateFields },
this.options.writeOperationOptions
{ writeConcern: this.options.writeOperationOptions }
)
if (rawResp.matchedCount === 0) {
return callback(new Error('Unable to find the session to touch'))
Expand Down Expand Up @@ -499,7 +503,7 @@ export default class MongoStore extends session.Store {
.then((colleciton) =>
colleciton.deleteOne(
{ _id: this.computeStorageId(sid) },
this.options.writeOperationOptions
{ writeConcern: this.options.writeOperationOptions }
)
)
.then(() => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,10 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256"
integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==

"@types/mongodb@^3.6.3":
version "3.6.3"
resolved "https://registry.yarnpkg.com/@types/mongodb/-/mongodb-3.6.3.tgz#5655af409d9e32d5d5ae9a653abf3e5f9c83eb7a"
integrity sha512-6YNqGP1hk5bjUFaim+QoFFuI61WjHiHE1BNeB41TA00Xd2K7zG4lcWyLLq/XtIp36uMavvS5hoAUJ+1u/GcX2Q==
"@types/mongodb@^3.6.18":
version "3.6.18"
resolved "https://registry.yarnpkg.com/@types/mongodb/-/mongodb-3.6.18.tgz#7524c462fc7e3b67892afda8211cd045edee65eb"
integrity sha512-JSVFt9p0rTfZ4EgzXmVHUB3ue00xe3CRbQho8nXfImzEDDM4O7I3po1bwbWl/EIbLENxUreZxqLOc8lvcnLVPA==
dependencies:
"@types/bson" "*"
"@types/node" "*"
Expand Down

0 comments on commit cceec18

Please sign in to comment.