@toa.io/storages.mongodb 1.0.0-alpha.208 → 1.0.0-alpha.209
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 +23 -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.209",
|
|
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.173",
|
|
28
28
|
"saslprep": "1.0.3"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "56601872d17c8f154afae932e9516459b42e6703"
|
|
31
31
|
}
|
package/src/storage.js
CHANGED
|
@@ -125,10 +125,29 @@ class Storage extends Connector {
|
|
|
125
125
|
const operations = entities.map((entity) => {
|
|
126
126
|
const record = to(entity)
|
|
127
127
|
|
|
128
|
-
if (entity._version === 1)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return {
|
|
128
|
+
if (entity._version === 1) {
|
|
129
|
+
const { _version, ...rest } = record
|
|
130
|
+
|
|
131
|
+
return { // upsert in required when document is deleted
|
|
132
|
+
updateOne: {
|
|
133
|
+
filter: { _id: entity.id },
|
|
134
|
+
update: {
|
|
135
|
+
$set: {
|
|
136
|
+
...rest,
|
|
137
|
+
_deleted: null
|
|
138
|
+
},
|
|
139
|
+
$inc: { _version: 1 },
|
|
140
|
+
},
|
|
141
|
+
upsert: true
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} else
|
|
145
|
+
return {
|
|
146
|
+
replaceOne: {
|
|
147
|
+
filter: { _id: entity.id, _version: entity._version - 1 },
|
|
148
|
+
replacement: record
|
|
149
|
+
}
|
|
150
|
+
}
|
|
132
151
|
})
|
|
133
152
|
|
|
134
153
|
const client = this.#client.instance.client
|