Compare commits
2 Commits
84ba3423e2
...
308c9cb63d
Author | SHA1 | Date | |
---|---|---|---|
308c9cb63d | |||
2cd8ba3ba0 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@navy.gif/wrappers",
|
"name": "@navy.gif/wrappers",
|
||||||
"version": "1.5.5",
|
"version": "1.5.6",
|
||||||
"description": "Various wrapper classes I use in my projects",
|
"description": "Various wrapper classes I use in my projects",
|
||||||
"repository": "https://git.corgi.wtf/Navy.gif/wrappers.git",
|
"repository": "https://git.corgi.wtf/Navy.gif/wrappers.git",
|
||||||
"author": "Navy.gif",
|
"author": "Navy.gif",
|
||||||
|
@ -363,13 +363,21 @@ class MongoDB
|
|||||||
return this.#db.collection(coll).countDocuments(query);
|
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)
|
if (!this.#db)
|
||||||
throw new Error('MongoDB not connected');
|
return Promise.reject(new Error('MongoDB not connected'));
|
||||||
if (!(indices instanceof Array))
|
if (!(index instanceof Array))
|
||||||
indices = [ indices ];
|
index = [ index ];
|
||||||
await this.#db.collection(collection).createIndex(indices, options);
|
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