allow index options

This commit is contained in:
Erik 2023-05-08 21:28:00 +03:00
parent 42c0cd4bcc
commit 91aa37b003
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68

View File

@ -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);
}
}