@opra/mongodb 1.26.3 → 1.27.0
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 +24 -1
- package/adapter/mongo-adapter.d.ts +45 -0
- package/adapter/mongo-adapter.js +23 -0
- package/adapter/mongo-patch-generator.d.ts +12 -0
- package/adapter/mongo-patch-generator.js +22 -10
- package/adapter/prepare-filter.d.ts +4 -6
- package/adapter/prepare-filter.js +4 -6
- package/adapter/prepare-key-values.d.ts +9 -0
- package/adapter/prepare-key-values.js +9 -0
- package/adapter/prepare-projection.d.ts +8 -0
- package/adapter/prepare-projection.js +13 -5
- package/adapter/prepare-sort.d.ts +6 -0
- package/adapter/prepare-sort.js +6 -0
- package/package.json +4 -4
- package/services/mongo-collection-service.d.ts +133 -84
- package/services/mongo-collection-service.js +36 -38
- package/services/mongo-entity-service.d.ts +71 -23
- package/services/mongo-entity-service.js +39 -40
- package/services/mongo-nested-service.d.ts +136 -87
- package/services/mongo-nested-service.js +62 -70
- package/services/mongo-service.d.ts +60 -34
- package/services/mongo-service.js +10 -15
- package/services/mongo-singleton-service.d.ts +49 -46
- package/services/mongo-singleton-service.js +25 -28
- package/types.d.ts +9 -3
|
@@ -1,50 +1,47 @@
|
|
|
1
1
|
import { ExecutionContext, ServiceBase } from '@opra/core';
|
|
2
2
|
import mongodb, { type UpdateFilter } from 'mongodb';
|
|
3
|
-
import type { Nullish, PartialDTO, RequiredSome, Type } from 'ts-gems';
|
|
3
|
+
import type { DTO, Nullish, PartialDTO, RequiredSome, Type } from 'ts-gems';
|
|
4
4
|
import { MongoAdapter } from '../adapter/mongo-adapter.js';
|
|
5
5
|
import type { MongoPatchDTO } from '../types.js';
|
|
6
6
|
import { MongoEntityService } from './mongo-entity-service.js';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @namespace MongoCollectionService
|
|
8
|
+
* Options for MongoCollectionService.
|
|
10
9
|
*/
|
|
11
10
|
export declare namespace MongoCollectionService {
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @interface Options
|
|
16
|
-
* @extends MongoService.Options
|
|
12
|
+
* Configuration options for MongoCollectionService.
|
|
17
13
|
*/
|
|
18
14
|
interface Options extends MongoEntityService.Options {
|
|
15
|
+
/**
|
|
16
|
+
* Default maximum number of records returned by `findMany`.
|
|
17
|
+
*/
|
|
19
18
|
defaultLimit?: number;
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Service for managing a collection of entities backed by a MongoDB data source.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The entity type managed by this service.
|
|
25
25
|
*/
|
|
26
26
|
export declare class MongoCollectionService<T extends mongodb.Document> extends MongoEntityService<T> {
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @type {number}
|
|
28
|
+
* Default maximum number of records returned by `findMany`.
|
|
31
29
|
*/
|
|
32
30
|
defaultLimit: number;
|
|
33
31
|
/**
|
|
34
|
-
* Constructs a new instance
|
|
32
|
+
* Constructs a new instance.
|
|
35
33
|
*
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @constructor
|
|
34
|
+
* @param dataType - The entity class or its registered name.
|
|
35
|
+
* @param options - Options for the collection service.
|
|
39
36
|
*/
|
|
40
37
|
constructor(dataType: Type | string, options?: MongoCollectionService.Options);
|
|
41
38
|
/**
|
|
42
39
|
* Create a copy of this instance with given properties and context applied.
|
|
43
40
|
*
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
-
* @
|
|
41
|
+
* @param context - The execution context or service base to associate with this instance.
|
|
42
|
+
* @param [overwriteProperties] - An optional object containing properties to overwrite in the current instance.
|
|
43
|
+
* @param [overwriteContext] - An optional partial context to apply and potentially overwrite parts of the provided execution context.
|
|
44
|
+
* @returns The current instance with the specified properties and context applied.
|
|
48
45
|
* @template P
|
|
49
46
|
* @template C
|
|
50
47
|
*/
|
|
@@ -53,156 +50,208 @@ export declare class MongoCollectionService<T extends mongodb.Document> extends
|
|
|
53
50
|
* Asserts the existence of a resource with the given ID.
|
|
54
51
|
* Throws a ResourceNotFoundError if the resource does not exist.
|
|
55
52
|
*
|
|
56
|
-
* @param
|
|
57
|
-
* @param
|
|
58
|
-
* @returns
|
|
59
|
-
* @throws {ResourceNotAvailableError} - If the resource does not exist.
|
|
53
|
+
* @param id - The ID of the resource to assert.
|
|
54
|
+
* @param options - Optional options for checking the existence.
|
|
55
|
+
* @returns A Promise that resolves when the resource exists.
|
|
56
|
+
* @throws {@link ResourceNotAvailableError} - If the resource does not exist.
|
|
60
57
|
*/
|
|
61
58
|
assert(id: MongoAdapter.AnyId, options?: MongoEntityService.ExistsOptions<T>): Promise<void>;
|
|
62
59
|
/**
|
|
63
60
|
* Creates a new document in the MongoDB collection.
|
|
64
|
-
* Interceptors will be called before performing db operation
|
|
61
|
+
* Interceptors will be called before performing db operation.
|
|
65
62
|
*
|
|
66
|
-
* @param
|
|
67
|
-
* @param
|
|
68
|
-
* @returns
|
|
69
|
-
* @throws {Error} if an unknown error occurs while creating the document.
|
|
63
|
+
* @param input - The input data for creating the document.
|
|
64
|
+
* @param options - The options for creating the document.
|
|
65
|
+
* @returns A promise that resolves to the created document.
|
|
66
|
+
* @throws {@link Error} if an unknown error occurs while creating the document.
|
|
70
67
|
*/
|
|
71
68
|
create(input: PartialDTO<T> | T, options: RequiredSome<MongoEntityService.CreateOptions, 'projection'>): Promise<PartialDTO<T>>;
|
|
72
69
|
create(input: PartialDTO<T> | T, options?: MongoEntityService.CreateOptions): Promise<T>;
|
|
73
70
|
/**
|
|
74
71
|
* Returns the count of documents in the collection based on the provided options.
|
|
75
72
|
*
|
|
76
|
-
* @param
|
|
77
|
-
* @
|
|
73
|
+
* @param options - The options for the count operation.
|
|
74
|
+
* @returns A promise that resolves to the count of documents in the collection.
|
|
78
75
|
*/
|
|
79
76
|
count(options?: MongoEntityService.CountOptions<T>): Promise<number>;
|
|
80
77
|
/**
|
|
81
78
|
* Deletes a document from the collection.
|
|
82
79
|
*
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
85
|
-
* @
|
|
80
|
+
* @param id - The ID of the document to delete.
|
|
81
|
+
* @param [options] - Optional delete options.
|
|
82
|
+
* @returns A Promise that resolves to the number of documents deleted.
|
|
86
83
|
*/
|
|
87
84
|
delete(id: MongoAdapter.AnyId, options?: MongoEntityService.DeleteOptions<T>): Promise<number>;
|
|
88
85
|
/**
|
|
89
86
|
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
90
87
|
*
|
|
91
|
-
* @param
|
|
92
|
-
* @
|
|
88
|
+
* @param options - The options for the delete operation.
|
|
89
|
+
* @returns A promise that resolves to the number of documents deleted.
|
|
93
90
|
*/
|
|
94
91
|
deleteMany(options?: MongoEntityService.DeleteManyOptions<T>): Promise<number>;
|
|
95
92
|
/**
|
|
96
93
|
* The distinct command returns a list of distinct values for the given key across a collection.
|
|
97
|
-
* @param
|
|
98
|
-
* @param
|
|
94
|
+
* @param field - The field to get distinct values for.
|
|
95
|
+
* @param [options] - The options for the distinct operation.
|
|
99
96
|
* @protected
|
|
100
97
|
*/
|
|
101
98
|
distinct(field: string, options?: MongoEntityService.DistinctOptions<T>): Promise<any[]>;
|
|
102
99
|
/**
|
|
103
100
|
* Checks if an object with the given id exists.
|
|
104
101
|
*
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
107
|
-
* @
|
|
102
|
+
* @param id - The id of the object to check.
|
|
103
|
+
* @param [options] - The options for the query (optional).
|
|
104
|
+
* @returns A Promise that resolves to a boolean indicating whether the object exists or not.
|
|
108
105
|
*/
|
|
109
106
|
exists(id: MongoAdapter.AnyId, options?: MongoEntityService.ExistsOptions<T>): Promise<boolean>;
|
|
110
107
|
/**
|
|
111
108
|
* Checks if an object with the given arguments exists.
|
|
112
109
|
*
|
|
113
|
-
* @param
|
|
114
|
-
* @
|
|
110
|
+
* @param [options] - The options for the query (optional).
|
|
111
|
+
* @returns A Promise that resolves to a boolean indicating whether the object exists or not.
|
|
115
112
|
*/
|
|
116
113
|
existsOne(options?: MongoEntityService.ExistsOptions<T>): Promise<boolean>;
|
|
117
114
|
/**
|
|
118
|
-
* Finds a document by its ID.
|
|
115
|
+
* Finds a document by its ID and returns it with the requested projection.
|
|
119
116
|
*
|
|
120
|
-
* @param
|
|
121
|
-
* @param
|
|
122
|
-
* @
|
|
117
|
+
* @param id - The ID of the document to find.
|
|
118
|
+
* @param options - Options including a required `projection`.
|
|
119
|
+
* @returns A promise that resolves to the found document as a partial DTO, or `undefined` if not found.
|
|
123
120
|
*/
|
|
124
121
|
findById(id: MongoAdapter.AnyId, options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
|
|
122
|
+
/**
|
|
123
|
+
* Finds a document by its ID and returns the whole DTO.
|
|
124
|
+
*
|
|
125
|
+
* @param id - The ID of the document to find.
|
|
126
|
+
* @param options - Optional query options.
|
|
127
|
+
* @returns A promise that resolves to the found document as a full DTO, or `undefined` if not found.
|
|
128
|
+
*/
|
|
125
129
|
findById(id: MongoAdapter.AnyId, options?: MongoEntityService.FindOneOptions<T>): Promise<T | undefined>;
|
|
126
130
|
/**
|
|
127
131
|
* Finds a document in the collection that matches the specified options.
|
|
128
132
|
*
|
|
129
|
-
* @param
|
|
130
|
-
* @
|
|
133
|
+
* @param [options] - The options for the query.
|
|
134
|
+
* @returns A promise that resolves with the found document or undefined if no document is found.
|
|
135
|
+
*/
|
|
136
|
+
/**
|
|
137
|
+
* Finds the first record matching the given options and returns it with the requested projection.
|
|
138
|
+
*
|
|
139
|
+
* @param options - Options including a required `projection`.
|
|
140
|
+
* @returns A promise that resolves to the found record as a partial DTO, or `undefined` if not found.
|
|
131
141
|
*/
|
|
132
142
|
findOne(options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
|
|
143
|
+
/**
|
|
144
|
+
* Finds the first record matching the given options and returns the whole DTO.
|
|
145
|
+
*
|
|
146
|
+
* @param options - Optional query options.
|
|
147
|
+
* @returns A promise that resolves to the found record, or `undefined` if not found.
|
|
148
|
+
*/
|
|
133
149
|
findOne(options?: MongoEntityService.FindOneOptions<T>): Promise<T | undefined>;
|
|
134
150
|
/**
|
|
135
|
-
* Finds multiple documents
|
|
151
|
+
* Finds multiple documents matching the given options and returns them with the requested projection.
|
|
136
152
|
*
|
|
137
|
-
* @param
|
|
138
|
-
* @
|
|
153
|
+
* @param options - Options including a required `projection`.
|
|
154
|
+
* @returns A promise that resolves to an array of matching documents as partial DTOs.
|
|
139
155
|
*/
|
|
140
156
|
findMany(options: RequiredSome<MongoEntityService.FindManyOptions<T>, 'projection'>): Promise<PartialDTO<T>[]>;
|
|
141
|
-
findMany(options?: MongoEntityService.FindManyOptions<T>): Promise<T[]>;
|
|
142
157
|
/**
|
|
143
|
-
* Finds multiple documents
|
|
144
|
-
*
|
|
158
|
+
* Finds multiple documents matching the given options and returns them as whole DTOs.
|
|
159
|
+
*
|
|
160
|
+
* @param options - Optional query options.
|
|
161
|
+
* @returns A promise that resolves to an array of matching documents as whole DTOs.
|
|
162
|
+
*/
|
|
163
|
+
findMany(options?: MongoEntityService.FindManyOptions<T>): Promise<DTO<T>[]>;
|
|
164
|
+
/**
|
|
165
|
+
* Finds multiple documents matching the given options and returns them with the total count.
|
|
145
166
|
*
|
|
146
|
-
* @param
|
|
147
|
-
* @
|
|
167
|
+
* @param options - Options including a required `projection`.
|
|
168
|
+
* @returns An object containing the items (as partial DTOs) and the total count.
|
|
148
169
|
*/
|
|
149
170
|
findManyWithCount(options: RequiredSome<MongoEntityService.FindManyOptions<T>, 'projection'>): Promise<{
|
|
150
171
|
count: number;
|
|
151
172
|
items: PartialDTO<T>[];
|
|
152
173
|
}>;
|
|
174
|
+
/**
|
|
175
|
+
* Finds multiple documents matching the given options and returns them with the total count.
|
|
176
|
+
*
|
|
177
|
+
* @param options - Optional query options.
|
|
178
|
+
* @returns An object containing the items (as full DTOs) and the total count.
|
|
179
|
+
*/
|
|
153
180
|
findManyWithCount(options?: MongoEntityService.FindManyOptions<T>): Promise<{
|
|
154
181
|
count: number;
|
|
155
|
-
items: T[];
|
|
182
|
+
items: DTO<T>[];
|
|
156
183
|
}>;
|
|
157
184
|
/**
|
|
158
|
-
* Retrieves a document
|
|
185
|
+
* Retrieves a document by its ID and returns it with the requested projection.
|
|
186
|
+
* Throws a ResourceNotAvailableError if the document does not exist.
|
|
159
187
|
*
|
|
160
|
-
* @param
|
|
161
|
-
* @param
|
|
162
|
-
* @returns
|
|
163
|
-
*
|
|
164
|
-
* @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
|
|
188
|
+
* @param id - The ID of the document to retrieve.
|
|
189
|
+
* @param options - Options including a required `projection`.
|
|
190
|
+
* @returns A promise that resolves to the retrieved document as a partial DTO.
|
|
191
|
+
* @throws {@link ResourceNotAvailableError} If the document does not exist.
|
|
165
192
|
*/
|
|
166
193
|
get(id: MongoAdapter.AnyId, options: RequiredSome<MongoEntityService.FindOneOptions<T>, 'projection'>): Promise<PartialDTO<T>>;
|
|
194
|
+
/**
|
|
195
|
+
* Retrieves a document by its ID and returns the whole DTO.
|
|
196
|
+
* Throws a ResourceNotAvailableError if the document does not exist.
|
|
197
|
+
*
|
|
198
|
+
* @param id - The ID of the document to retrieve.
|
|
199
|
+
* @param options - Optional query options.
|
|
200
|
+
* @returns A promise that resolves to the retrieved document as a full DTO.
|
|
201
|
+
* @throws {@link ResourceNotAvailableError} If the document does not exist.
|
|
202
|
+
*/
|
|
167
203
|
get(id: MongoAdapter.AnyId, options?: MongoEntityService.FindOneOptions<T>): Promise<T>;
|
|
168
204
|
/**
|
|
169
|
-
*
|
|
170
|
-
* Interceptors will be called before performing db operation
|
|
205
|
+
* Replaces a document by its ID and returns it with the requested projection.
|
|
171
206
|
*
|
|
172
|
-
* @param
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
175
|
-
* @returns
|
|
176
|
-
* @throws {Error} if an unknown error occurs while replacing the document.
|
|
207
|
+
* @param id - The ID of the document to replace.
|
|
208
|
+
* @param input - The replacement document data.
|
|
209
|
+
* @param options - Options including a required `projection`.
|
|
210
|
+
* @returns A promise that resolves to the replaced document as a partial DTO, or `undefined` if not found.
|
|
177
211
|
*/
|
|
178
212
|
replace(id: MongoAdapter.AnyId, input: PartialDTO<T>, options: RequiredSome<MongoEntityService.ReplaceOptions<T>, 'projection'>): Promise<PartialDTO<T>>;
|
|
213
|
+
/**
|
|
214
|
+
* Replaces a document by its ID and returns the whole replaced DTO.
|
|
215
|
+
*
|
|
216
|
+
* @param id - The ID of the document to replace.
|
|
217
|
+
* @param input - The replacement document data.
|
|
218
|
+
* @param options - Optional replace options.
|
|
219
|
+
* @returns A promise that resolves to the replaced document as a full DTO, or `undefined` if not found.
|
|
220
|
+
*/
|
|
179
221
|
replace(id: MongoAdapter.AnyId, input: PartialDTO<T>, options?: MongoEntityService.CreateOptions): Promise<T>;
|
|
180
222
|
/**
|
|
181
|
-
* Updates a document
|
|
223
|
+
* Updates a document by its ID and returns it with the requested projection.
|
|
182
224
|
*
|
|
183
|
-
* @param
|
|
184
|
-
* @param
|
|
185
|
-
* @param
|
|
186
|
-
* @returns
|
|
187
|
-
* undefined if the document was not found.
|
|
225
|
+
* @param id - The ID of the document to update.
|
|
226
|
+
* @param input - The fields to update.
|
|
227
|
+
* @param options - Options including a required `projection`.
|
|
228
|
+
* @returns A promise that resolves to the updated document as a partial DTO, or `undefined` if not found.
|
|
188
229
|
*/
|
|
189
230
|
update(id: MongoAdapter.AnyId, input: MongoPatchDTO<T> | UpdateFilter<T>, options: RequiredSome<MongoEntityService.UpdateOneOptions<T>, 'projection'>): Promise<PartialDTO<T> | undefined>;
|
|
231
|
+
/**
|
|
232
|
+
* Updates a document by its ID and returns the whole updated DTO.
|
|
233
|
+
*
|
|
234
|
+
* @param id - The ID of the document to update.
|
|
235
|
+
* @param input - The fields to update.
|
|
236
|
+
* @param options - Optional update options.
|
|
237
|
+
* @returns A promise that resolves to the updated document as a full DTO, or `undefined` if not found.
|
|
238
|
+
*/
|
|
190
239
|
update(id: MongoAdapter.AnyId, input: MongoPatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<T | undefined>;
|
|
191
240
|
/**
|
|
192
241
|
* Updates a document in the collection with the specified ID.
|
|
193
242
|
*
|
|
194
|
-
* @param
|
|
195
|
-
* @param
|
|
196
|
-
* @param
|
|
197
|
-
* @returns
|
|
243
|
+
* @param id - The ID of the document to update.
|
|
244
|
+
* @param input - The partial input data to update the document with.
|
|
245
|
+
* @param [options] - The options for updating the document.
|
|
246
|
+
* @returns A promise that resolves to the number of documents modified.
|
|
198
247
|
*/
|
|
199
248
|
updateOnly(id: MongoAdapter.AnyId, input: MongoPatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateOneOptions<T>): Promise<number>;
|
|
200
249
|
/**
|
|
201
250
|
* Updates multiple documents in the collection based on the specified input and options.
|
|
202
251
|
*
|
|
203
|
-
* @param
|
|
204
|
-
* @param
|
|
205
|
-
* @
|
|
252
|
+
* @param input - The partial input to update the documents with.
|
|
253
|
+
* @param [options] - The options for updating the documents.
|
|
254
|
+
* @returns A promise that resolves to the number of documents matched and modified.
|
|
206
255
|
*/
|
|
207
256
|
updateMany(input: MongoPatchDTO<T> | UpdateFilter<T>, options?: MongoEntityService.UpdateManyOptions<T>): Promise<number>;
|
|
208
257
|
}
|
|
@@ -2,22 +2,20 @@ import { ResourceNotAvailableError } from '@opra/common';
|
|
|
2
2
|
import { MongoAdapter } from '../adapter/mongo-adapter.js';
|
|
3
3
|
import { MongoEntityService } from './mongo-entity-service.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Service for managing a collection of entities backed by a MongoDB data source.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The entity type managed by this service.
|
|
7
8
|
*/
|
|
8
9
|
export class MongoCollectionService extends MongoEntityService {
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @type {number}
|
|
11
|
+
* Default maximum number of records returned by `findMany`.
|
|
13
12
|
*/
|
|
14
13
|
defaultLimit;
|
|
15
14
|
/**
|
|
16
|
-
* Constructs a new instance
|
|
15
|
+
* Constructs a new instance.
|
|
17
16
|
*
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
* @constructor
|
|
17
|
+
* @param dataType - The entity class or its registered name.
|
|
18
|
+
* @param options - Options for the collection service.
|
|
21
19
|
*/
|
|
22
20
|
constructor(dataType, options) {
|
|
23
21
|
super(dataType, options);
|
|
@@ -26,10 +24,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
26
24
|
/**
|
|
27
25
|
* Create a copy of this instance with given properties and context applied.
|
|
28
26
|
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @
|
|
27
|
+
* @param context - The execution context or service base to associate with this instance.
|
|
28
|
+
* @param [overwriteProperties] - An optional object containing properties to overwrite in the current instance.
|
|
29
|
+
* @param [overwriteContext] - An optional partial context to apply and potentially overwrite parts of the provided execution context.
|
|
30
|
+
* @returns The current instance with the specified properties and context applied.
|
|
33
31
|
* @template P
|
|
34
32
|
* @template C
|
|
35
33
|
*/
|
|
@@ -40,10 +38,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
40
38
|
* Asserts the existence of a resource with the given ID.
|
|
41
39
|
* Throws a ResourceNotFoundError if the resource does not exist.
|
|
42
40
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @returns
|
|
46
|
-
* @throws {ResourceNotAvailableError} - If the resource does not exist.
|
|
41
|
+
* @param id - The ID of the resource to assert.
|
|
42
|
+
* @param options - Optional options for checking the existence.
|
|
43
|
+
* @returns A Promise that resolves when the resource exists.
|
|
44
|
+
* @throws {@link ResourceNotAvailableError} - If the resource does not exist.
|
|
47
45
|
*/
|
|
48
46
|
async assert(id, options) {
|
|
49
47
|
if (!(await this.exists(id, options)))
|
|
@@ -78,8 +76,8 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
78
76
|
/**
|
|
79
77
|
* Returns the count of documents in the collection based on the provided options.
|
|
80
78
|
*
|
|
81
|
-
* @param
|
|
82
|
-
* @
|
|
79
|
+
* @param options - The options for the count operation.
|
|
80
|
+
* @returns A promise that resolves to the count of documents in the collection.
|
|
83
81
|
*/
|
|
84
82
|
async count(options) {
|
|
85
83
|
const command = {
|
|
@@ -103,9 +101,9 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
103
101
|
/**
|
|
104
102
|
* Deletes a document from the collection.
|
|
105
103
|
*
|
|
106
|
-
* @param
|
|
107
|
-
* @param
|
|
108
|
-
* @
|
|
104
|
+
* @param id - The ID of the document to delete.
|
|
105
|
+
* @param [options] - Optional delete options.
|
|
106
|
+
* @returns A Promise that resolves to the number of documents deleted.
|
|
109
107
|
*/
|
|
110
108
|
async delete(id, options) {
|
|
111
109
|
const command = {
|
|
@@ -130,8 +128,8 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
130
128
|
/**
|
|
131
129
|
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
132
130
|
*
|
|
133
|
-
* @param
|
|
134
|
-
* @
|
|
131
|
+
* @param options - The options for the delete operation.
|
|
132
|
+
* @returns A promise that resolves to the number of documents deleted.
|
|
135
133
|
*/
|
|
136
134
|
async deleteMany(options) {
|
|
137
135
|
const command = {
|
|
@@ -154,8 +152,8 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
154
152
|
}
|
|
155
153
|
/**
|
|
156
154
|
* The distinct command returns a list of distinct values for the given key across a collection.
|
|
157
|
-
* @param
|
|
158
|
-
* @param
|
|
155
|
+
* @param field - The field to get distinct values for.
|
|
156
|
+
* @param [options] - The options for the distinct operation.
|
|
159
157
|
* @protected
|
|
160
158
|
*/
|
|
161
159
|
async distinct(field, options) {
|
|
@@ -181,9 +179,9 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
181
179
|
/**
|
|
182
180
|
* Checks if an object with the given id exists.
|
|
183
181
|
*
|
|
184
|
-
* @param
|
|
185
|
-
* @param
|
|
186
|
-
* @
|
|
182
|
+
* @param id - The id of the object to check.
|
|
183
|
+
* @param [options] - The options for the query (optional).
|
|
184
|
+
* @returns A Promise that resolves to a boolean indicating whether the object exists or not.
|
|
187
185
|
*/
|
|
188
186
|
async exists(id, options) {
|
|
189
187
|
const command = {
|
|
@@ -213,8 +211,8 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
213
211
|
/**
|
|
214
212
|
* Checks if an object with the given arguments exists.
|
|
215
213
|
*
|
|
216
|
-
* @param
|
|
217
|
-
* @
|
|
214
|
+
* @param [options] - The options for the query (optional).
|
|
215
|
+
* @returns A Promise that resolves to a boolean indicating whether the object exists or not.
|
|
218
216
|
*/
|
|
219
217
|
async existsOne(options) {
|
|
220
218
|
return !!(await this.findOne({ ...options, projection: ['_id'] }));
|
|
@@ -356,10 +354,10 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
356
354
|
/**
|
|
357
355
|
* Updates a document in the collection with the specified ID.
|
|
358
356
|
*
|
|
359
|
-
* @param
|
|
360
|
-
* @param
|
|
361
|
-
* @param
|
|
362
|
-
* @returns
|
|
357
|
+
* @param id - The ID of the document to update.
|
|
358
|
+
* @param input - The partial input data to update the document with.
|
|
359
|
+
* @param [options] - The options for updating the document.
|
|
360
|
+
* @returns A promise that resolves to the number of documents modified.
|
|
363
361
|
*/
|
|
364
362
|
async updateOnly(id, input, options) {
|
|
365
363
|
const isUpdateFilter = Array.isArray(input) || !!Object.keys(input).find(x => x.startsWith('$'));
|
|
@@ -387,9 +385,9 @@ export class MongoCollectionService extends MongoEntityService {
|
|
|
387
385
|
/**
|
|
388
386
|
* Updates multiple documents in the collection based on the specified input and options.
|
|
389
387
|
*
|
|
390
|
-
* @param
|
|
391
|
-
* @param
|
|
392
|
-
* @
|
|
388
|
+
* @param input - The partial input to update the documents with.
|
|
389
|
+
* @param [options] - The options for updating the documents.
|
|
390
|
+
* @returns A promise that resolves to the number of documents matched and modified.
|
|
393
391
|
*/
|
|
394
392
|
async updateMany(input, options) {
|
|
395
393
|
const isUpdateFilter = Array.isArray(input) || !!Object.keys(input).find(x => x.startsWith('$'));
|