@travetto/model-mongo 8.0.4 → 8.0.5
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.
- package/README.md +1 -1
- package/package.json +2 -2
- package/src/service.ts +3 -13
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Supported features:
|
|
|
21
21
|
* [CRUD](https://github.com/travetto/travetto/tree/main/module/model/src/types/crud.ts#L10)
|
|
22
22
|
* [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/types/expiry.ts#L10)
|
|
23
23
|
* [Indexed](https://github.com/travetto/travetto/tree/main/module/model-indexed/src/types/service.ts#L21)
|
|
24
|
-
* [Aggregate](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/aggregate.ts#
|
|
24
|
+
* [Aggregate](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/aggregate.ts#L56)
|
|
25
25
|
* [Query Crud](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/crud.ts#L11)
|
|
26
26
|
* [Facet](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/facet.ts#L14)
|
|
27
27
|
* [Suggest](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/suggest.ts#L12)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-mongo",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.5",
|
|
4
4
|
"description": "Mongo backing for the travetto model module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"database",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@travetto/config": "^8.0.3",
|
|
33
33
|
"@travetto/model": "^8.0.3",
|
|
34
34
|
"@travetto/model-indexed": "^8.0.3",
|
|
35
|
-
"@travetto/model-query": "^8.0.
|
|
35
|
+
"@travetto/model-query": "^8.0.5",
|
|
36
36
|
"mongodb": "^7.6.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
package/src/service.ts
CHANGED
|
@@ -63,10 +63,10 @@ import {
|
|
|
63
63
|
ModelQuerySuggestUtil,
|
|
64
64
|
type ModelQuerySupport,
|
|
65
65
|
ModelQueryUtil,
|
|
66
|
+
type NumberFieldAggregateResult,
|
|
66
67
|
type PageableModelQuery,
|
|
67
68
|
QueryVerifier,
|
|
68
69
|
type ValidComparableFields,
|
|
69
|
-
type ValidNumericFields,
|
|
70
70
|
type ValidStringFields,
|
|
71
71
|
type WhereClause
|
|
72
72
|
} from '@travetto/model-query';
|
|
@@ -80,7 +80,6 @@ import {
|
|
|
80
80
|
type Class,
|
|
81
81
|
castTo,
|
|
82
82
|
JSONUtil,
|
|
83
|
-
RuntimeError,
|
|
84
83
|
ShutdownManager,
|
|
85
84
|
TypedObject
|
|
86
85
|
} from '@travetto/runtime';
|
|
@@ -738,7 +737,7 @@ export class MongoModelService
|
|
|
738
737
|
}
|
|
739
738
|
|
|
740
739
|
// Aggregate
|
|
741
|
-
async aggregateFieldByQuery<T extends ModelType, F extends ValidComparableFields<T>>(
|
|
740
|
+
async aggregateFieldByQuery<T extends ModelType, const F extends ValidComparableFields<T>>(
|
|
742
741
|
cls: Class<T>,
|
|
743
742
|
field: F,
|
|
744
743
|
query?: ModelQuery<T>
|
|
@@ -769,16 +768,7 @@ export class MongoModelService
|
|
|
769
768
|
|
|
770
769
|
const aggregations: object[] = [{ $match: queryObject }, { $group: groupFields }];
|
|
771
770
|
|
|
772
|
-
const result = await collection
|
|
773
|
-
.aggregate<{
|
|
774
|
-
_id: null;
|
|
775
|
-
count?: number;
|
|
776
|
-
min?: unknown;
|
|
777
|
-
max?: unknown;
|
|
778
|
-
avg?: unknown;
|
|
779
|
-
sum?: unknown;
|
|
780
|
-
}>(aggregations)
|
|
781
|
-
.toArray();
|
|
771
|
+
const result = await collection.aggregate<NumberFieldAggregateResult>(aggregations).toArray();
|
|
782
772
|
|
|
783
773
|
const row = result.length ? result[0] : { count: 0 };
|
|
784
774
|
return ModelQueryAggregateUtil.resolveAggregate(cls, field, row);
|