Compare commits
2 Commits
84ba3423e2
...
308c9cb63d
Author | SHA1 | Date | |
---|---|---|---|
308c9cb63d | |||
2cd8ba3ba0 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navy.gif/wrappers",
|
||||
"version": "1.5.5",
|
||||
"version": "1.5.6",
|
||||
"description": "Various wrapper classes I use in my projects",
|
||||
"repository": "https://git.corgi.wtf/Navy.gif/wrappers.git",
|
||||
"author": "Navy.gif",
|
||||
|
@ -363,13 +363,21 @@ class MongoDB
|
||||
return this.#db.collection(coll).countDocuments(query);
|
||||
}
|
||||
|
||||
async ensureIndex (collection: string, indices: IndexSpecification = [], options?: CreateIndexesOptions)
|
||||
async ensureIndex (collection: string, index: IndexSpecification, options?: CreateIndexesOptions): Promise<void>
|
||||
{
|
||||
if (!this.#db)
|
||||
throw new Error('MongoDB not connected');
|
||||
if (!(indices instanceof Array))
|
||||
indices = [ indices ];
|
||||
await this.#db.collection(collection).createIndex(indices, options);
|
||||
return Promise.reject(new Error('MongoDB not connected'));
|
||||
if (!(index instanceof Array))
|
||||
index = [ index ];
|
||||
await this.#db.collection(collection).createIndex(index, options);
|
||||
}
|
||||
|
||||
async ensureIndices (collection: string, indices: IndexSpecification[], options?: CreateIndexesOptions): Promise<void>
|
||||
{
|
||||
if (!this.#db)
|
||||
return Promise.reject(new Error('MongoDB not connected'));
|
||||
for (const index of indices)
|
||||
await this.ensureIndex(collection, index, options);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user