type params for methods
This commit is contained in:
parent
37a54d9932
commit
c0eae8be4b
@ -301,7 +301,7 @@ class MongoDB {
|
||||
* @returns {object}
|
||||
* @memberof Database
|
||||
*/
|
||||
random (db: string, filter: Document = {}, amount = 1) {
|
||||
random<T extends Document> (db: string, filter: Document = {}, amount = 1) {
|
||||
|
||||
if (!this.#db)
|
||||
throw new Error(`MongoDB not connected`);
|
||||
@ -315,7 +315,7 @@ class MongoDB {
|
||||
if (amount > 100)
|
||||
amount = 100;
|
||||
|
||||
const cursor = this.#db.collection(db).aggregate([{ $match: filter }, { $sample: { size: amount } }]);
|
||||
const cursor = this.#db.collection(db).aggregate<T>([{ $match: filter }, { $sample: { size: amount } }]);
|
||||
return cursor.toArray();
|
||||
|
||||
}
|
||||
@ -327,10 +327,10 @@ class MongoDB {
|
||||
return result;
|
||||
}
|
||||
|
||||
collection (coll: string) {
|
||||
collection<T extends Document> (coll: string) {
|
||||
if (!this.#db)
|
||||
throw new Error(`MongoDB not connected`);
|
||||
return this.#db.collection(coll);
|
||||
return this.#db.collection<T>(coll);
|
||||
}
|
||||
|
||||
count (coll: string, query: Document) {
|
||||
|
Loading…
Reference in New Issue
Block a user