wingbot-mongodb 4.0.0-alpha.1 → 4.0.0-alpha.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot-mongodb",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "MongoDB storage for wingbot.ai",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
@@ -4,7 +4,7 @@
4
4
  'use strict';
5
5
 
6
6
  const { ObjectId } = require('mongodb');
7
- const { default: assert } = require('assert');
7
+ const { strict: assert } = require('assert');
8
8
  const crypto = require('crypto');
9
9
  const defaultLogger = require('./defaultLogger');
10
10
 
@@ -134,6 +134,7 @@ class BaseStorage {
134
134
 
135
135
  this._indexing = null;
136
136
  this._shouldIndexBeforeRead = null;
137
+ this._shouldWaitForIndex = null;
137
138
  }
138
139
 
139
140
  /**
@@ -261,6 +262,9 @@ class BaseStorage {
261
262
  }
262
263
 
263
264
  this._shouldIndexBeforeRead = this._fixtures.length !== 0;
265
+ this._shouldWaitForIndex = this._isCosmo
266
+ || this._shouldIndexBeforeRead
267
+ || this._indexes.some((i) => i.options.unique);
264
268
 
265
269
  this._indexing = this._ensureIndexes(this._indexes, collection)
266
270
  .then(() => {
@@ -296,7 +300,10 @@ class BaseStorage {
296
300
  }
297
301
  }
298
302
 
299
- if (this._indexing && (!forRead || this._shouldIndexBeforeRead)) {
303
+ if (this._indexing
304
+ && this._shouldWaitForIndex
305
+ && (!forRead || this._shouldIndexBeforeRead)) {
306
+
300
307
  const err = await this._indexing;
301
308
  this._indexing = false;
302
309
  if (err) throw err;