@toa.io/storages.mongodb 1.0.0-alpha.66 → 1.0.0-alpha.68

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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/storage.js +23 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/storages.mongodb",
3
- "version": "1.0.0-alpha.66",
3
+ "version": "1.0.0-alpha.68",
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",
@@ -20,12 +20,12 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@toa.io/conveyor": "1.0.0-alpha.63",
23
- "@toa.io/core": "1.0.0-alpha.66",
23
+ "@toa.io/core": "1.0.0-alpha.67",
24
24
  "@toa.io/generic": "1.0.0-alpha.63",
25
25
  "@toa.io/pointer": "1.0.0-alpha.63",
26
26
  "mongodb": "6.7.0",
27
- "openspan": "1.0.0-alpha.66",
27
+ "openspan": "1.0.0-alpha.67",
28
28
  "saslprep": "1.0.3"
29
29
  },
30
- "gitHead": "e5052ee5ae7ac87d6c96a40026c3cd7cef6c11fe"
30
+ "gitHead": "5906cac0be7d9802090d4670e16ee71cb03aedc4"
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
- return await this.#collection.find(criteria, options).stream({ transform: from })
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 result = await this.#collection.findOneAndReplace(criteria, to(entity))
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)
@@ -154,6 +173,8 @@ class Storage extends Connector {
154
173
 
155
174
  const sparse = this.checkFields(Object.keys(fields))
156
175
 
176
+ console.debug('Database query', { method: 'createIndex', fields, name, sparse })
177
+
157
178
  await this.#collection.createIndex(fields, { name, sparse })
158
179
 
159
180
  indexes.push(name)