allow index options
This commit is contained in:
parent
42c0cd4bcc
commit
91aa37b003
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user