diff --git a/src/MongoDB.ts b/src/MongoDB.ts index aa4aff0..4ab8afa 100644 --- a/src/MongoDB.ts +++ b/src/MongoDB.ts @@ -386,6 +386,10 @@ class MongoDB if (!(index instanceof Array)) 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 existing = indexes.find(idx => idx.name.startsWith(index)); if (existing && this.#indexesEqual(existing, options))