From 91aa37b00398e4088b31dbfee415f4a39fb4c061 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 8 May 2023 21:28:00 +0300 Subject: [PATCH] allow index options --- src/MongoDB.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MongoDB.ts b/src/MongoDB.ts index 996b05f..75c720b 100644 --- a/src/MongoDB.ts +++ b/src/MongoDB.ts @@ -1,5 +1,5 @@ import { inspect } from "node:util"; -import { MongoClient, MongoClientOptions, Db, Document, WithId, ObjectId, Filter, IndexSpecification } from "mongodb"; +import { MongoClient, MongoClientOptions, Db, Document, WithId, ObjectId, Filter, IndexSpecification, CreateIndexesOptions } from "mongodb"; import { IServer, ILogger, LoggerClientOptions } from "./interfaces/index.js"; type Credentials = { @@ -333,12 +333,12 @@ class MongoDB { return this.#db.collection(coll); } - async ensureIndex (collection: string, indices: IndexSpecification = []) { + async ensureIndex (collection: string, indices: IndexSpecification = [], options?: CreateIndexesOptions) { if (!this.#db) throw new Error(`MongoDB not connected`); if (!(indices instanceof Array)) indices = [ indices ]; - await this.#db.collection(collection).createIndex(indices); + await this.#db.collection(collection).createIndex(indices, options); } }