@toa.io/storages.mongodb 1.0.0-alpha.20 → 1.0.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/src/client.js +16 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/storages.mongodb",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.22",
|
|
4
4
|
"description": "Toa MongoDB Storage Connector",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@toa.io/console": "1.0.0-alpha.
|
|
23
|
-
"@toa.io/conveyor": "1.0.0-alpha.
|
|
24
|
-
"@toa.io/core": "1.0.0-alpha.
|
|
25
|
-
"@toa.io/generic": "1.0.0-alpha.
|
|
26
|
-
"@toa.io/pointer": "1.0.0-alpha.
|
|
22
|
+
"@toa.io/console": "1.0.0-alpha.22",
|
|
23
|
+
"@toa.io/conveyor": "1.0.0-alpha.22",
|
|
24
|
+
"@toa.io/core": "1.0.0-alpha.22",
|
|
25
|
+
"@toa.io/generic": "1.0.0-alpha.22",
|
|
26
|
+
"@toa.io/pointer": "1.0.0-alpha.22",
|
|
27
27
|
"mongodb": "6.3.0",
|
|
28
28
|
"saslprep": "1.0.3"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "5bc67b81c4c5fbf92db037c805fba84a571ed24b"
|
|
31
31
|
}
|
package/src/client.js
CHANGED
|
@@ -57,17 +57,27 @@ class Client extends Connector {
|
|
|
57
57
|
*/
|
|
58
58
|
async open () {
|
|
59
59
|
const urls = await this.resolveURLs()
|
|
60
|
-
const
|
|
61
|
-
const
|
|
60
|
+
const dbname = this.resolveDB()
|
|
61
|
+
const collname = this.locator.lowercase
|
|
62
62
|
|
|
63
|
-
this.key = getKey(
|
|
63
|
+
this.key = getKey(dbname, urls)
|
|
64
64
|
|
|
65
65
|
INSTANCES[this.key] ??= this.createInstance(urls)
|
|
66
66
|
|
|
67
67
|
this.instance = await INSTANCES[this.key]
|
|
68
68
|
this.instance.count++
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
const db = this.instance.client.db(dbname)
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
this.collection = await db.createCollection(collname)
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (e.code !== ALREADY_EXISTS) {
|
|
76
|
+
throw e
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.collection = db.collection(collname)
|
|
80
|
+
}
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
/**
|
|
@@ -144,4 +154,6 @@ const OPTIONS = {
|
|
|
144
154
|
serverSelectionTimeoutMS: 0
|
|
145
155
|
}
|
|
146
156
|
|
|
157
|
+
const ALREADY_EXISTS = 48
|
|
158
|
+
|
|
147
159
|
exports.Client = Client
|