@mikro-orm/mongodb 7.1.0-dev.31 → 7.1.0-dev.33
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/MongoConnection.d.ts +12 -7
- package/MongoConnection.js +26 -13
- package/MongoDriver.d.ts +3 -2
- package/MongoDriver.js +13 -10
- package/MongoEntityManager.js +3 -3
- package/package.json +2 -2
package/MongoConnection.d.ts
CHANGED
|
@@ -28,13 +28,13 @@ export declare class MongoConnection extends Connection {
|
|
|
28
28
|
find<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, opts?: MongoFindOptions<T>): Promise<EntityData<T>[]>;
|
|
29
29
|
stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, opts?: MongoFindOptions<T>): AsyncIterableIterator<T>;
|
|
30
30
|
private _find;
|
|
31
|
-
insertOne<T extends object>(entityName: EntityName<T>, data: Partial<T>, ctx?: Transaction<ClientSession
|
|
32
|
-
insertMany<T extends object>(entityName: EntityName<T>, data: Partial<T>[], ctx?: Transaction<ClientSession
|
|
33
|
-
updateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, data: Partial<T>, ctx?: Transaction<ClientSession>, upsert?: boolean, upsertOptions?: UpsertOptions<T
|
|
34
|
-
bulkUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: Partial<T>[], ctx?: Transaction<ClientSession>, upsert?: boolean, upsertOptions?: UpsertManyOptions<T
|
|
35
|
-
deleteMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, ctx?: Transaction<ClientSession
|
|
36
|
-
aggregate<T extends object = any>(entityName: EntityName<T>, pipeline: any[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions): Promise<T[]>;
|
|
37
|
-
streamAggregate<T extends object>(entityName: EntityName<T>, pipeline: any[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions, stream?: boolean): AsyncIterableIterator<T>;
|
|
31
|
+
insertOne<T extends object>(entityName: EntityName<T>, data: Partial<T>, ctx?: Transaction<ClientSession>, signal?: AbortSignal): Promise<QueryResult<T>>;
|
|
32
|
+
insertMany<T extends object>(entityName: EntityName<T>, data: Partial<T>[], ctx?: Transaction<ClientSession>, signal?: AbortSignal): Promise<QueryResult<T>>;
|
|
33
|
+
updateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, data: Partial<T>, ctx?: Transaction<ClientSession>, upsert?: boolean, upsertOptions?: UpsertOptions<T>, signal?: AbortSignal): Promise<QueryResult<T>>;
|
|
34
|
+
bulkUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: Partial<T>[], ctx?: Transaction<ClientSession>, upsert?: boolean, upsertOptions?: UpsertManyOptions<T>, signal?: AbortSignal): Promise<QueryResult<T>>;
|
|
35
|
+
deleteMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, ctx?: Transaction<ClientSession>, signal?: AbortSignal): Promise<QueryResult<T>>;
|
|
36
|
+
aggregate<T extends object = any>(entityName: EntityName<T>, pipeline: any[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions, signal?: AbortSignal): Promise<T[]>;
|
|
37
|
+
streamAggregate<T extends object>(entityName: EntityName<T>, pipeline: any[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions, stream?: boolean, signal?: AbortSignal): AsyncIterableIterator<T>;
|
|
38
38
|
countDocuments<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, opts?: MongoCountOptions): Promise<number>;
|
|
39
39
|
transactional<T>(cb: (trx: Transaction<ClientSession>) => Promise<T>, options?: {
|
|
40
40
|
isolationLevel?: IsolationLevel;
|
|
@@ -61,6 +61,11 @@ export interface MongoQueryOptions {
|
|
|
61
61
|
indexHint?: string | Dictionary;
|
|
62
62
|
maxTimeMS?: number;
|
|
63
63
|
allowDiskUse?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Forwarded to the MongoDB driver. When fired, the driver aborts the in-flight operation
|
|
66
|
+
* by closing the underlying socket; the rejection reason is `signal.reason`.
|
|
67
|
+
*/
|
|
68
|
+
signal?: AbortSignal;
|
|
64
69
|
}
|
|
65
70
|
/** Options for MongoDB find operations. */
|
|
66
71
|
export interface MongoFindOptions<T extends object> extends MongoQueryOptions {
|
package/MongoConnection.js
CHANGED
|
@@ -146,6 +146,9 @@ export class MongoConnection extends Connection {
|
|
|
146
146
|
if (opts.chunkSize != null) {
|
|
147
147
|
options.batchSize = opts.chunkSize;
|
|
148
148
|
}
|
|
149
|
+
if (opts.signal) {
|
|
150
|
+
options.signal = opts.signal;
|
|
151
|
+
}
|
|
149
152
|
const resultSet = this.getCollection(entityName).find(where, options);
|
|
150
153
|
let query = `db.getCollection('${collection}').find(${this.logObject(where)}, ${this.logObject(options)})`;
|
|
151
154
|
const orderBy = Utils.asArray(opts.orderBy);
|
|
@@ -177,37 +180,43 @@ export class MongoConnection extends Connection {
|
|
|
177
180
|
}
|
|
178
181
|
return { cursor: resultSet, query };
|
|
179
182
|
}
|
|
180
|
-
async insertOne(entityName, data, ctx) {
|
|
181
|
-
return this.runQuery('insertOne', entityName, data, undefined, ctx);
|
|
183
|
+
async insertOne(entityName, data, ctx, signal) {
|
|
184
|
+
return this.runQuery('insertOne', entityName, data, undefined, ctx, { signal });
|
|
182
185
|
}
|
|
183
|
-
async insertMany(entityName, data, ctx) {
|
|
184
|
-
return this.runQuery('insertMany', entityName, data, undefined, ctx);
|
|
186
|
+
async insertMany(entityName, data, ctx, signal) {
|
|
187
|
+
return this.runQuery('insertMany', entityName, data, undefined, ctx, { signal });
|
|
185
188
|
}
|
|
186
|
-
async updateMany(entityName, where, data, ctx, upsert, upsertOptions) {
|
|
187
|
-
return this.runQuery('updateMany', entityName, data, where, ctx, { upsert, upsertOptions });
|
|
189
|
+
async updateMany(entityName, where, data, ctx, upsert, upsertOptions, signal) {
|
|
190
|
+
return this.runQuery('updateMany', entityName, data, where, ctx, { upsert, upsertOptions, signal });
|
|
188
191
|
}
|
|
189
|
-
async bulkUpdateMany(entityName, where, data, ctx, upsert, upsertOptions) {
|
|
190
|
-
return this.runQuery('bulkUpdateMany', entityName, data, where, ctx, { upsert, upsertOptions });
|
|
192
|
+
async bulkUpdateMany(entityName, where, data, ctx, upsert, upsertOptions, signal) {
|
|
193
|
+
return this.runQuery('bulkUpdateMany', entityName, data, where, ctx, { upsert, upsertOptions, signal });
|
|
191
194
|
}
|
|
192
|
-
async deleteMany(entityName, where, ctx) {
|
|
193
|
-
return this.runQuery('deleteMany', entityName, undefined, where, ctx);
|
|
195
|
+
async deleteMany(entityName, where, ctx, signal) {
|
|
196
|
+
return this.runQuery('deleteMany', entityName, undefined, where, ctx, { signal });
|
|
194
197
|
}
|
|
195
|
-
async aggregate(entityName, pipeline, ctx, loggerContext) {
|
|
198
|
+
async aggregate(entityName, pipeline, ctx, loggerContext, signal) {
|
|
196
199
|
await this.ensureConnection();
|
|
197
200
|
const collection = this.getCollectionName(entityName);
|
|
198
201
|
/* v8 ignore next */
|
|
199
202
|
const options = ctx ? { session: ctx } : {};
|
|
203
|
+
if (signal) {
|
|
204
|
+
options.signal = signal;
|
|
205
|
+
}
|
|
200
206
|
const query = `db.getCollection('${collection}').aggregate(${this.logObject(pipeline)}, ${this.logObject(options)}).toArray();`;
|
|
201
207
|
const now = Date.now();
|
|
202
208
|
const res = await this.getCollection(entityName).aggregate(pipeline, options).toArray();
|
|
203
209
|
this.logQuery(query, { took: Date.now() - now, results: res.length, ...loggerContext });
|
|
204
210
|
return res;
|
|
205
211
|
}
|
|
206
|
-
async *streamAggregate(entityName, pipeline, ctx, loggerContext, stream = false) {
|
|
212
|
+
async *streamAggregate(entityName, pipeline, ctx, loggerContext, stream = false, signal) {
|
|
207
213
|
await this.ensureConnection();
|
|
208
214
|
const collection = this.getCollectionName(entityName);
|
|
209
215
|
/* v8 ignore next */
|
|
210
216
|
const options = ctx ? { session: ctx } : {};
|
|
217
|
+
if (signal) {
|
|
218
|
+
options.signal = signal;
|
|
219
|
+
}
|
|
211
220
|
const query = `db.getCollection('${collection}').aggregate(${this.logObject(pipeline)}, ${this.logObject(options)})};`;
|
|
212
221
|
const cursor = this.getCollection(entityName).aggregate(pipeline, options);
|
|
213
222
|
this.logQuery(query, { ...loggerContext });
|
|
@@ -219,6 +228,7 @@ export class MongoConnection extends Connection {
|
|
|
219
228
|
collation: opts.collation,
|
|
220
229
|
indexHint: opts.indexHint,
|
|
221
230
|
maxTimeMS: opts.maxTimeMS,
|
|
231
|
+
signal: opts.signal,
|
|
222
232
|
});
|
|
223
233
|
}
|
|
224
234
|
async transactional(cb, options = {}) {
|
|
@@ -265,13 +275,16 @@ export class MongoConnection extends Connection {
|
|
|
265
275
|
}
|
|
266
276
|
async runQuery(method, entityName, data, where, ctx, opts) {
|
|
267
277
|
await this.ensureConnection();
|
|
268
|
-
const { upsert, upsertOptions, loggerContext, collation, indexHint, maxTimeMS } = opts ?? {};
|
|
278
|
+
const { upsert, upsertOptions, loggerContext, collation, indexHint, maxTimeMS, signal } = opts ?? {};
|
|
269
279
|
const collection = this.getCollectionName(entityName);
|
|
270
280
|
const logger = this.config.getLogger();
|
|
271
281
|
const options = ctx ? { session: ctx, upsert } : { upsert };
|
|
272
282
|
if (options.upsert === undefined) {
|
|
273
283
|
delete options.upsert;
|
|
274
284
|
}
|
|
285
|
+
if (signal) {
|
|
286
|
+
options.signal = signal;
|
|
287
|
+
}
|
|
275
288
|
const now = Date.now();
|
|
276
289
|
let res;
|
|
277
290
|
let query;
|
package/MongoDriver.d.ts
CHANGED
|
@@ -27,9 +27,10 @@ export declare class MongoDriver extends DatabaseDriver<MongoConnection> {
|
|
|
27
27
|
nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>;
|
|
28
28
|
nativeDelete<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options?: {
|
|
29
29
|
ctx?: Transaction<ClientSession>;
|
|
30
|
+
signal?: AbortSignal;
|
|
30
31
|
}): Promise<QueryResult<T>>;
|
|
31
|
-
aggregate(entityName: EntityName, pipeline: any[], ctx?: Transaction<ClientSession
|
|
32
|
-
streamAggregate<T extends object>(entityName: EntityName<T>, pipeline: any[], ctx?: Transaction<ClientSession
|
|
32
|
+
aggregate(entityName: EntityName, pipeline: any[], ctx?: Transaction<ClientSession>, signal?: AbortSignal): Promise<any[]>;
|
|
33
|
+
streamAggregate<T extends object>(entityName: EntityName<T>, pipeline: any[], ctx?: Transaction<ClientSession>, signal?: AbortSignal): AsyncIterableIterator<T>;
|
|
33
34
|
getPlatform(): MongoPlatform;
|
|
34
35
|
private buildQueryOptions;
|
|
35
36
|
/** @internal */
|
package/MongoDriver.js
CHANGED
|
@@ -132,7 +132,7 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
132
132
|
}
|
|
133
133
|
pipeline.push({ $project: projection });
|
|
134
134
|
}
|
|
135
|
-
const res = await this.rethrow(this.getConnection('read').aggregate(entityName, pipeline, options.ctx, options.logging));
|
|
135
|
+
const res = await this.rethrow(this.getConnection('read').aggregate(entityName, pipeline, options.ctx, options.logging, options.signal));
|
|
136
136
|
return res.map(r => this.mapResult(r, meta));
|
|
137
137
|
}
|
|
138
138
|
async findOne(entityName, where, options = { populate: [], orderBy: {} }) {
|
|
@@ -193,7 +193,7 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
193
193
|
async nativeInsert(entityName, data, options = {}) {
|
|
194
194
|
this.handleVersionProperty(entityName, data);
|
|
195
195
|
data = this.renameFields(entityName, data);
|
|
196
|
-
return this.rethrow(this.getConnection('write').insertOne(entityName, data, options.ctx));
|
|
196
|
+
return this.rethrow(this.getConnection('write').insertOne(entityName, data, options.ctx, options.signal));
|
|
197
197
|
}
|
|
198
198
|
async nativeClone(entityName, where, overrides, options = {}) {
|
|
199
199
|
const meta = this.metadata.find(entityName);
|
|
@@ -224,7 +224,7 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
224
224
|
const meta = this.metadata.find(entityName);
|
|
225
225
|
/* v8 ignore next */
|
|
226
226
|
const pk = meta?.getPrimaryProps()[0].fieldNames[0] ?? '_id';
|
|
227
|
-
const res = await this.rethrow(this.getConnection('write').insertMany(entityName, data, options.ctx));
|
|
227
|
+
const res = await this.rethrow(this.getConnection('write').insertMany(entityName, data, options.ctx, options.signal));
|
|
228
228
|
res.rows = res.insertedIds.map(id => ({ [pk]: id }));
|
|
229
229
|
return res;
|
|
230
230
|
}
|
|
@@ -248,7 +248,7 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
248
248
|
if (options.onConflictExcludeFields) {
|
|
249
249
|
options.onConflictExcludeFields = options.onConflictExcludeFields.map(rename);
|
|
250
250
|
}
|
|
251
|
-
return this.rethrow(this.getConnection('write').updateMany(entityName, where, data, options.ctx, options.upsert, options));
|
|
251
|
+
return this.rethrow(this.getConnection('write').updateMany(entityName, where, data, options.ctx, options.upsert, options, options.signal));
|
|
252
252
|
}
|
|
253
253
|
async nativeUpdateMany(entityName, where, data, options = {}) {
|
|
254
254
|
where = where.map(row => {
|
|
@@ -276,7 +276,7 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
276
276
|
}
|
|
277
277
|
/* v8 ignore next */
|
|
278
278
|
const pk = meta?.getPrimaryProps()[0].fieldNames[0] ?? '_id';
|
|
279
|
-
const res = await this.rethrow(this.getConnection('write').bulkUpdateMany(entityName, where, data, options.ctx, options.upsert, options));
|
|
279
|
+
const res = await this.rethrow(this.getConnection('write').bulkUpdateMany(entityName, where, data, options.ctx, options.upsert, options, options.signal));
|
|
280
280
|
if (res.insertedIds) {
|
|
281
281
|
let i = 0;
|
|
282
282
|
res.rows = where.map(cond => {
|
|
@@ -293,13 +293,13 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
293
293
|
where = this.buildFilterById(entityName, where);
|
|
294
294
|
}
|
|
295
295
|
where = this.renameFields(entityName, where, true);
|
|
296
|
-
return this.rethrow(this.getConnection('write').deleteMany(entityName, where, options.ctx));
|
|
296
|
+
return this.rethrow(this.getConnection('write').deleteMany(entityName, where, options.ctx, options.signal));
|
|
297
297
|
}
|
|
298
|
-
async aggregate(entityName, pipeline, ctx) {
|
|
299
|
-
return this.rethrow(this.getConnection('read').aggregate(entityName, pipeline, ctx));
|
|
298
|
+
async aggregate(entityName, pipeline, ctx, signal) {
|
|
299
|
+
return this.rethrow(this.getConnection('read').aggregate(entityName, pipeline, ctx, undefined, signal));
|
|
300
300
|
}
|
|
301
|
-
async *streamAggregate(entityName, pipeline, ctx) {
|
|
302
|
-
yield* this.getConnection('read').streamAggregate(entityName, pipeline, ctx);
|
|
301
|
+
async *streamAggregate(entityName, pipeline, ctx, signal) {
|
|
302
|
+
yield* this.getConnection('read').streamAggregate(entityName, pipeline, ctx, undefined, false, signal);
|
|
303
303
|
}
|
|
304
304
|
getPlatform() {
|
|
305
305
|
return this.platform;
|
|
@@ -328,6 +328,9 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
328
328
|
if (options.allowDiskUse != null) {
|
|
329
329
|
ret.allowDiskUse = options.allowDiskUse;
|
|
330
330
|
}
|
|
331
|
+
if (options.signal) {
|
|
332
|
+
ret.signal = options.signal;
|
|
333
|
+
}
|
|
331
334
|
return ret;
|
|
332
335
|
}
|
|
333
336
|
/** @internal */
|
package/MongoEntityManager.js
CHANGED
|
@@ -7,13 +7,13 @@ export class MongoEntityManager extends EntityManager {
|
|
|
7
7
|
* Shortcut to driver's aggregate method. Available in MongoDriver only.
|
|
8
8
|
*/
|
|
9
9
|
async aggregate(entityName, pipeline) {
|
|
10
|
-
return this.getDriver().aggregate(entityName, pipeline, this.getTransactionContext());
|
|
10
|
+
return this.getDriver().aggregate(entityName, pipeline, this.getTransactionContext(), this.signal);
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Shortcut to driver's aggregate method. Returns a stream. Available in MongoDriver only.
|
|
14
14
|
*/
|
|
15
15
|
async *streamAggregate(entityName, pipeline) {
|
|
16
|
-
yield* this.getDriver().streamAggregate(entityName, pipeline, this.getTransactionContext());
|
|
16
|
+
yield* this.getDriver().streamAggregate(entityName, pipeline, this.getTransactionContext(), this.signal);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* @inheritDoc
|
|
@@ -50,7 +50,7 @@ export class MongoEntityManager extends EntityManager {
|
|
|
50
50
|
pipeline.push({ $match: renamedWhere });
|
|
51
51
|
}
|
|
52
52
|
pipeline.push({ $group: { _id: groupId, count: { $sum: 1 } } });
|
|
53
|
-
const rows = await em.getDriver().aggregate(meta.class, pipeline, em.getTransactionContext());
|
|
53
|
+
const rows = await em.getDriver().aggregate(meta.class, pipeline, em.getTransactionContext(), em.signal);
|
|
54
54
|
const results = {};
|
|
55
55
|
for (const row of rows) {
|
|
56
56
|
const key = fieldNames.length === 1 ? String(row._id) : fieldNames.map(f => String(row._id[f])).join(Utils.PK_SEPARATOR);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mongodb",
|
|
3
|
-
"version": "7.1.0-dev.
|
|
3
|
+
"version": "7.1.0-dev.33",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.0.15"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.0-dev.33"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|