Compare commits
No commits in common. "55c91289872859196e3dcef62c1a532326db4b46" and "3d877bc1c97330b562e63743aafceda44016c2c0" have entirely different histories.
55c9128987
...
3d877bc1c9
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navy.gif/wrappers",
|
||||
"version": "1.6.1",
|
||||
"version": "1.5.12",
|
||||
"description": "Various wrapper classes I use in my projects",
|
||||
"repository": "https://git.corgi.wtf/Navy.gif/wrappers.git",
|
||||
"author": "Navy.gif",
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { inspect } from 'node:util';
|
||||
import { MongoClient, MongoClientOptions, Db, Document, WithId, ObjectId, Filter, IndexSpecification, CreateIndexesOptions, FindOptions, ModifyResult } from 'mongodb';
|
||||
import { MongoClient, MongoClientOptions, Db, Document, WithId, ObjectId, Filter, IndexSpecification, CreateIndexesOptions, FindOptions } from 'mongodb';
|
||||
import { IServer, ILogger, LoggerClientOptions } from './interfaces/index.js';
|
||||
|
||||
type Credentials = {
|
||||
@ -288,6 +288,7 @@ class MongoDB
|
||||
|
||||
async deleteOne (db: string, filter: Document)
|
||||
{
|
||||
|
||||
if (!this.#db)
|
||||
throw new Error('MongoDB not connected');
|
||||
if (typeof db !== 'string')
|
||||
@ -298,21 +299,7 @@ class MongoDB
|
||||
this.#logger.debug(`Incoming deleteOne query for ${db} with parameters ${inspect(filter)}`);
|
||||
const result = await this.#db.collection(db).deleteOne(filter);
|
||||
return result;
|
||||
}
|
||||
|
||||
async findOneAndDelete<T extends Document> (db: string, filter: Document, meta: false): Promise<WithId<T>>
|
||||
async findOneAndDelete<T extends Document> (db: string, filter: Document, meta: true): Promise<ModifyResult<T>>
|
||||
async findOneAndDelete<T extends Document> (db: string, filter: Document, meta = false)
|
||||
{
|
||||
if (!this.#db)
|
||||
throw new Error('MongoDB not connected');
|
||||
if (typeof db !== 'string')
|
||||
throw new TypeError('Expecting collection name for the first argument');
|
||||
if (typeof filter._id === 'string')
|
||||
filter._id = new ObjectId(filter._id);
|
||||
|
||||
const result = await this.#db.collection<T>(db).findOneAndDelete(filter as Filter<T>, { includeResultMetadata: meta });
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -399,10 +386,6 @@ class MongoDB
|
||||
if (!(index instanceof Array))
|
||||
index = [ index ];
|
||||
|
||||
const collections = await this.#db.collections();
|
||||
if (!collections.some((coll) => coll.namespace.split('.')[1] === collection))
|
||||
await this.#db.createCollection(collection);
|
||||
|
||||
const indexes = await this.#db.collection(collection).indexes();
|
||||
const existing = indexes.find(idx => idx.name.startsWith(index));
|
||||
if (existing && this.#indexesEqual(existing, options))
|
||||
|
Loading…
Reference in New Issue
Block a user