Repository: Yoctol/bottender
Pull request #510 (2019-11-07 08:29:29)

fix: mongo updateOne issue
according to 
https://github.com/mongodb/node-mongodb-native/blob/master/CHANGES_3.0.0.md#updateone--updatemany

We should add $set in this case, in order to avoid the error.

codecov-io: # [Codecov](https://codecov.io/gh/Yoctol/bottender/pull/510?src=pr&el=h1) Report
> Merging [#510](https://codecov.io/gh/Yoctol/bottender/pull/510?src=pr&el=desc) into [develop](https://codecov.io/gh/Yoctol/bottender/commit/3b1ec7a2737192ad2e17f53251f488aaab9d1819?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/Yoctol/bottender/pull/510/graphs/tree.svg?width=650&token=JX3EGtxYH3&height=150&src=pr)](https://codecov.io/gh/Yoctol/bottender/pull/510?src=pr&el=tree)

```diff
@@           Coverage Diff            @@
##           develop     #510   +/-   ##
========================================
  Coverage    82.07%   82.07%           
========================================
  Files           97       97           
  Lines         3933     3933           
  Branches       942      942           
========================================
  Hits          3228     3228           
  Misses         673      673           
  Partials        32       32
```


| [Impacted Files](https://codecov.io/gh/Yoctol/bottender/pull/510?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [...ackages/bottender/src/session/MongoSessionStore.ts](https://codecov.io/gh/Yoctol/bottender/pull/510/diff?src=pr&el=tree#diff-cGFja2FnZXMvYm90dGVuZGVyL3NyYy9zZXNzaW9uL01vbmdvU2Vzc2lvblN0b3JlLnRz) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Yoctol/bottender/pull/510?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Yoctol/bottender/pull/510?src=pr&el=footer). Last update [3b1ec7a...c495de8](https://codecov.io/gh/Yoctol/bottender/pull/510?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/packages/bottender/src/session/MongoSessionStore.ts b/packages/bottender/src/session/MongoSessionStore.ts
index 90e529f5..dd001652 100644
--- a/packages/bottender/src/session/MongoSessionStore.ts
+++ b/packages/bottender/src/session/MongoSessionStore.ts
@@ -67,9 +67,13 @@ export default class MongoSessionStore implements SessionStore {
     sess.lastActivity = Date.now();
 
     try {
-      await this._sessions.updateOne(filter, sess, {
-        upsert: true,
-      });
+      await this._sessions.updateOne(
+        filter,
+        { $set: sess },
+        {
+          upsert: true,
+        }
+      );
     } catch (err) {
       console.error(err);
     }


Test patch:
diff --git a/packages/bottender/src/session/__tests__/MongoSessionStore.spec.ts b/packages/bottender/src/session/__tests__/MongoSessionStore.spec.ts
index ded9e560..a28d1f6b 100644
--- a/packages/bottender/src/session/__tests__/MongoSessionStore.spec.ts
+++ b/packages/bottender/src/session/__tests__/MongoSessionStore.spec.ts
@@ -152,7 +152,9 @@ describe('#write', () => {
       {
         id: 'messenger:1',
       },
-      sess,
+      {
+        $set: sess,
+      },
       { upsert: true }
     );
   });