bugfix
make sure a collection exists before trying to create an index on it
This commit is contained in:
parent
3d877bc1c9
commit
44be4b491c
@ -386,6 +386,10 @@ class MongoDB
|
|||||||
if (!(index instanceof Array))
|
if (!(index instanceof Array))
|
||||||
index = [ index ];
|
index = [ index ];
|
||||||
|
|
||||||
|
const collections = await this.#db.collections();
|
||||||
|
if (!collections.some((coll) => coll.namespace.split('.')[1] === collection))
|
||||||
|
await this.#db.createCollection(collection);
|
||||||
|
|
||||||
const indexes = await this.#db.collection(collection).indexes();
|
const indexes = await this.#db.collection(collection).indexes();
|
||||||
const existing = indexes.find(idx => idx.name.startsWith(index));
|
const existing = indexes.find(idx => idx.name.startsWith(index));
|
||||||
if (existing && this.#indexesEqual(existing, options))
|
if (existing && this.#indexesEqual(existing, options))
|
||||||
|
Loading…
Reference in New Issue
Block a user