@toa.io/storages.mongodb 1.0.0-alpha.67 → 1.0.0-alpha.69
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 +2 -2
- package/src/storage.js +21 -2
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.69",
|
|
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",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"openspan": "1.0.0-alpha.67",
|
|
28
28
|
"saslprep": "1.0.3"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "1a23d550c737fbe1d4d2b960f9613c8a330d2de7"
|
|
31
31
|
}
|
package/src/storage.js
CHANGED
|
@@ -30,6 +30,9 @@ class Storage extends Connector {
|
|
|
30
30
|
|
|
31
31
|
async get (query) {
|
|
32
32
|
const { criteria, options } = translate(query)
|
|
33
|
+
|
|
34
|
+
console.debug('Database query', { method: 'findOne', criteria, options })
|
|
35
|
+
|
|
33
36
|
const record = await this.#collection.findOne(criteria, options)
|
|
34
37
|
|
|
35
38
|
return from(record)
|
|
@@ -37,6 +40,9 @@ class Storage extends Connector {
|
|
|
37
40
|
|
|
38
41
|
async find (query) {
|
|
39
42
|
const { criteria, options } = translate(query)
|
|
43
|
+
|
|
44
|
+
console.debug('Database query', { method: 'find', criteria, options })
|
|
45
|
+
|
|
40
46
|
const recordset = await this.#collection.find(criteria, options).toArray()
|
|
41
47
|
|
|
42
48
|
return recordset.map((item) => from(item))
|
|
@@ -45,11 +51,16 @@ class Storage extends Connector {
|
|
|
45
51
|
async stream (query = undefined) {
|
|
46
52
|
const { criteria, options } = translate(query)
|
|
47
53
|
|
|
48
|
-
|
|
54
|
+
console.debug('Database query', { method: 'find (stream)', criteria, options })
|
|
55
|
+
|
|
56
|
+
return this.#collection.find(criteria, options).stream({ transform: from })
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
async add (entity) {
|
|
52
60
|
const record = to(entity)
|
|
61
|
+
|
|
62
|
+
console.debug('Database query', { method: 'insertOne', record })
|
|
63
|
+
|
|
53
64
|
const result = await this.#collection.insertOne(record)
|
|
54
65
|
|
|
55
66
|
return result.acknowledged
|
|
@@ -61,7 +72,11 @@ class Storage extends Connector {
|
|
|
61
72
|
_version: entity._version - 1
|
|
62
73
|
}
|
|
63
74
|
|
|
64
|
-
const
|
|
75
|
+
const record = to(entity)
|
|
76
|
+
|
|
77
|
+
console.debug('Database query', { method: 'findOneAndReplace', criteria, record })
|
|
78
|
+
|
|
79
|
+
const result = await this.#collection.findOneAndReplace(criteria, record)
|
|
65
80
|
|
|
66
81
|
return result !== null
|
|
67
82
|
}
|
|
@@ -110,6 +125,8 @@ class Storage extends Connector {
|
|
|
110
125
|
|
|
111
126
|
options.returnDocument = ReturnDocument.AFTER
|
|
112
127
|
|
|
128
|
+
console.debug('Database query', { method: 'findOneAndUpdate', criteria, update, options })
|
|
129
|
+
|
|
113
130
|
const result = await this.#collection.findOneAndUpdate(criteria, update, options)
|
|
114
131
|
|
|
115
132
|
return from(result)
|
|
@@ -126,6 +143,8 @@ class Storage extends Connector {
|
|
|
126
143
|
options.upsert = true
|
|
127
144
|
options.returnDocument = ReturnDocument.AFTER
|
|
128
145
|
|
|
146
|
+
console.debug('Database query', { method: 'findOneAndUpdate', criteria, update, options })
|
|
147
|
+
|
|
129
148
|
const result = await this.#collection.findOneAndUpdate(criteria, update, options)
|
|
130
149
|
|
|
131
150
|
if (result._deleted !== undefined && result._deleted !== null)
|