@tmlmobilidade/interfaces 20250628.828.28 → 20250628.926.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -52,6 +52,12 @@ export declare abstract class MongoCollectionClass<T extends Document, TCreate,
|
|
|
52
52
|
* @returns A promise that resolves to an array of distinct values for the given key
|
|
53
53
|
*/
|
|
54
54
|
distinct<K extends keyof T>(key: K): Promise<T[K][]>;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a document with the given ID exists in the collection.
|
|
57
|
+
* @param id The ID of the document to check for existence.
|
|
58
|
+
* @returns A promise that resolves to true if the document exists, false otherwise.
|
|
59
|
+
*/
|
|
60
|
+
exists<K extends keyof T>(key: K, value: T[K]): Promise<boolean>;
|
|
55
61
|
/**
|
|
56
62
|
* Finds a document by its ID.
|
|
57
63
|
* @param id - The ID of the document to find
|
|
@@ -88,6 +88,16 @@ export class MongoCollectionClass {
|
|
|
88
88
|
async distinct(key) {
|
|
89
89
|
return this.mongoCollection.distinct(key);
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Checks if a document with the given ID exists in the collection.
|
|
93
|
+
* @param id The ID of the document to check for existence.
|
|
94
|
+
* @returns A promise that resolves to true if the document exists, false otherwise.
|
|
95
|
+
*/
|
|
96
|
+
async exists(key, value) {
|
|
97
|
+
const filter = { [key]: value };
|
|
98
|
+
const doc = await this.mongoCollection.findOne(filter, { projection: { [key]: 1 } });
|
|
99
|
+
return doc !== null;
|
|
100
|
+
}
|
|
91
101
|
/**
|
|
92
102
|
* Finds a document by its ID.
|
|
93
103
|
* @param id - The ID of the document to find
|
package/package.json
CHANGED