Repository: Yoctol/bottender
Pull request #512 (2019-11-08 03:43:15)

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.

tw0517tw: there are some lint and syntax issues
codecov-io: # [Codecov](https://codecov.io/gh/Yoctol/bottender/pull/512?src=pr&el=h1) Report
> Merging [#512](https://codecov.io/gh/Yoctol/bottender/pull/512?src=pr&el=desc) into [v0.16.x](https://codecov.io/gh/Yoctol/bottender/commit/2d53690e0b1012fd7843c48c4b41ae0943a5af46?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

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

```diff
@@           Coverage Diff            @@
##           v0.16.x     #512   +/-   ##
========================================
  Coverage    90.43%   90.43%           
========================================
  Files          121      121           
  Lines         3577     3577           
  Branches       803      803           
========================================
  Hits          3235     3235           
  Misses         300      300           
  Partials        42       42
```


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

------

[Continue to review full report at Codecov](https://codecov.io/gh/Yoctol/bottender/pull/512?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/512?src=pr&el=footer). Last update [2d53690...769777d](https://codecov.io/gh/Yoctol/bottender/pull/512?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/session/MongoSessionStore.js b/src/session/MongoSessionStore.js
index cb2e7b07..b6400177 100644
--- a/src/session/MongoSessionStore.js
+++ b/src/session/MongoSessionStore.js
@@ -75,9 +75,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/src/session/__tests__/MongoSessionStore.spec.js b/src/session/__tests__/MongoSessionStore.spec.js
index c23564df..c536cccf 100644
--- a/src/session/__tests__/MongoSessionStore.spec.js
+++ b/src/session/__tests__/MongoSessionStore.spec.js
@@ -141,7 +141,9 @@ describe('#write', () => {
       {
         id: 'messenger:1',
       },
-      sess,
+      {
+        $set: sess,
+      },
       { upsert: true }
     );
   });