Repository: Yoctol/bottender (ts)

Issue:
mongoose config is out of date
**Describe the bug**
creating a new bot with sessions-> mongoDB I get this message at the console:

```
(node:83117) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
(Use `node --trace-deprecation ...` to show where the warning was created)
```


```bash
npx create-bottender-app bot
npx: installed 63 in 7.906s
? What platform of bot do you want to create?
? Where do you want to store session? mongo
❯
❯ Creating a new Bottender bot at /Users/dc/dev/exiteer/xbot/bot.
❯
❯ Installing packages... This might take a couple of minutes.

....

$ npm run dev -- --console

> bot@0.1.0 dev /Users/dc/dev/exiteer/xbot/bot
> bottender dev "--console"

App has started
You > hi
hi
(node:83117) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
(Use `node --trace-deprecation ...` to show where the warning was created)
Bot > Welcome to Bottender
> hi
hi
Bot > Welcome to Bottender
```

**To Reproduce**
create new bot
run console


**Expected behavior**
This seems to be a [mongoose related issue](https://mongoosejs.com/docs/deprecations.html#:~:text=DeprecationWarning%3A%20current%20Server%20Discovery%20and,true%20%7D%20to%20the%20MongoClient%20constructor.&text=In%20MongoDB%20parlance%2C%20this%20is%20known%20as%20server%20discovery%20and%20monitoring.)

this should fix it:
```
mongoose.set('useUnifiedTopology', true);
```

perhaps somewhere around here?

https://github.com/Yoctol/bottender/blob/master/packages/bottender/src/session/MongoSessionStore.ts#L37



Pull request description:
fix(MongoSessionStore): enable useUnifiedTopology to avoid warning
Add `{ useUnifiedTopology: true }` to avoid breaking in the future. Fix #830.

See: https://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html#.connect

Patch:
diff --git a/packages/bottender/src/session/MongoSessionStore.ts b/packages/bottender/src/session/MongoSessionStore.ts
index 939637e6..94fcdfdd 100644
--- a/packages/bottender/src/session/MongoSessionStore.ts
+++ b/packages/bottender/src/session/MongoSessionStore.ts
@@ -34,7 +34,9 @@ export default class MongoSessionStore implements SessionStore {
   }
 
   async init(): Promise<MongoSessionStore> {
-    this._connection = (await MongoClient.connect(this._url)).db();
+    this._connection = (
+      await MongoClient.connect(this._url, { useUnifiedTopology: true })
+    ).db();
 
     return this;
   }


Test patch:
diff --git a/packages/bottender/src/session/__tests__/MongoSessionStore.spec.ts b/packages/bottender/src/session/__tests__/MongoSessionStore.spec.ts
index a28d1f6b..27938ce1 100644
--- a/packages/bottender/src/session/__tests__/MongoSessionStore.spec.ts
+++ b/packages/bottender/src/session/__tests__/MongoSessionStore.spec.ts
@@ -56,14 +56,9 @@ describe('#init', () => {
     const { store } = setup();
 
     await store.init();
-    expect(MongoClient.connect).toBeCalledWith('mongodb://fakemongourl');
-  });
-
-  it('should connect to provided url', async () => {
-    const { store } = setup();
-
-    await store.init();
-    expect(MongoClient.connect).toBeCalledWith('mongodb://fakemongourl');
+    expect(MongoClient.connect).toBeCalledWith('mongodb://fakemongourl', {
+      useUnifiedTopology: true,
+    });
   });
 });