@mikro-orm/mongodb 7.0.0-dev.114 → 7.0.0-dev.116

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.
@@ -24,17 +24,17 @@ export declare class MongoConnection extends Connection {
24
24
  mapOptions(overrides: MongoClientOptions): MongoClientOptions;
25
25
  getDb(): Db;
26
26
  execute(query: string): Promise<any>;
27
- find<T extends object>(collection: string, where: FilterQuery<T>, orderBy?: QueryOrderMap<T> | QueryOrderMap<T>[], limit?: number, offset?: number, fields?: string[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions): Promise<EntityData<T>[]>;
28
- stream<T extends object>(collection: string, where: FilterQuery<T>, orderBy?: QueryOrderMap<T> | QueryOrderMap<T>[], limit?: number, offset?: number, fields?: string[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions): AsyncIterableIterator<T>;
27
+ find<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, orderBy?: QueryOrderMap<T> | QueryOrderMap<T>[], limit?: number, offset?: number, fields?: string[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions): Promise<EntityData<T>[]>;
28
+ stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, orderBy?: QueryOrderMap<T> | QueryOrderMap<T>[], limit?: number, offset?: number, fields?: string[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions): AsyncIterableIterator<T>;
29
29
  private _find;
30
- insertOne<T extends object>(collection: string, data: Partial<T>, ctx?: Transaction<ClientSession>): Promise<QueryResult<T>>;
31
- insertMany<T extends object>(collection: string, data: Partial<T>[], ctx?: Transaction<ClientSession>): Promise<QueryResult<T>>;
32
- updateMany<T extends object>(collection: string, where: FilterQuery<T>, data: Partial<T>, ctx?: Transaction<ClientSession>, upsert?: boolean, upsertOptions?: UpsertOptions<T>): Promise<QueryResult<T>>;
33
- bulkUpdateMany<T extends object>(collection: string, where: FilterQuery<T>[], data: Partial<T>[], ctx?: Transaction<ClientSession>, upsert?: boolean, upsertOptions?: UpsertManyOptions<T>): Promise<QueryResult<T>>;
34
- deleteMany<T extends object>(collection: string, where: FilterQuery<T>, ctx?: Transaction<ClientSession>): Promise<QueryResult<T>>;
35
- aggregate<T extends object = any>(collection: string, pipeline: any[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions): Promise<T[]>;
36
- streamAggregate<T extends object>(collection: string, pipeline: any[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions, stream?: boolean): AsyncIterableIterator<T>;
37
- countDocuments<T extends object>(collection: string, where: FilterQuery<T>, ctx?: Transaction<ClientSession>): Promise<number>;
30
+ insertOne<T extends object>(entityName: EntityName<T>, data: Partial<T>, ctx?: Transaction<ClientSession>): Promise<QueryResult<T>>;
31
+ insertMany<T extends object>(entityName: EntityName<T>, data: Partial<T>[], ctx?: Transaction<ClientSession>): Promise<QueryResult<T>>;
32
+ updateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, data: Partial<T>, ctx?: Transaction<ClientSession>, upsert?: boolean, upsertOptions?: UpsertOptions<T>): Promise<QueryResult<T>>;
33
+ bulkUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: Partial<T>[], ctx?: Transaction<ClientSession>, upsert?: boolean, upsertOptions?: UpsertManyOptions<T>): Promise<QueryResult<T>>;
34
+ deleteMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, ctx?: Transaction<ClientSession>): Promise<QueryResult<T>>;
35
+ aggregate<T extends object = any>(entityName: EntityName<T>, pipeline: any[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions): Promise<T[]>;
36
+ streamAggregate<T extends object>(entityName: EntityName<T>, pipeline: any[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions, stream?: boolean): AsyncIterableIterator<T>;
37
+ countDocuments<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, ctx?: Transaction<ClientSession>): Promise<number>;
38
38
  transactional<T>(cb: (trx: Transaction<ClientSession>) => Promise<T>, options?: {
39
39
  isolationLevel?: IsolationLevel;
40
40
  ctx?: Transaction<ClientSession>;
@@ -1,5 +1,5 @@
1
1
  import { MongoClient, ObjectId, } from 'mongodb';
2
- import { Connection, EventType, QueryOrder, Utils, ValidationError, inspect, } from '@mikro-orm/core';
2
+ import { Connection, EventType, inspect, QueryOrder, Utils, ValidationError, } from '@mikro-orm/core';
3
3
  export class MongoConnection extends Connection {
4
4
  #client;
5
5
  #db;
@@ -111,26 +111,26 @@ export class MongoConnection extends Connection {
111
111
  async execute(query) {
112
112
  throw new Error(`${this.constructor.name} does not support generic execute method`);
113
113
  }
114
- async find(collection, where, orderBy, limit, offset, fields, ctx, loggerContext) {
115
- const { cursor, query } = await this._find(collection, where, orderBy, limit, offset, fields, ctx, loggerContext);
114
+ async find(entityName, where, orderBy, limit, offset, fields, ctx, loggerContext) {
115
+ const { cursor, query } = await this._find(entityName, where, orderBy, limit, offset, fields, ctx, loggerContext);
116
116
  const now = Date.now();
117
117
  const res = await cursor.toArray();
118
118
  this.logQuery(`${query}.toArray();`, { took: Date.now() - now, results: res.length, ...loggerContext });
119
119
  return res;
120
120
  }
121
- async *stream(collection, where, orderBy, limit, offset, fields, ctx, loggerContext) {
122
- const { cursor, query } = await this._find(collection, where, orderBy, limit, offset, fields, ctx, loggerContext);
121
+ async *stream(entityName, where, orderBy, limit, offset, fields, ctx, loggerContext) {
122
+ const { cursor, query } = await this._find(entityName, where, orderBy, limit, offset, fields, ctx, loggerContext);
123
123
  this.logQuery(`${query}.toArray();`, loggerContext);
124
124
  yield* cursor;
125
125
  }
126
- async _find(collection, where, orderBy, limit, offset, fields, ctx, loggerContext) {
126
+ async _find(entityName, where, orderBy, limit, offset, fields, ctx, loggerContext) {
127
127
  await this.ensureConnection();
128
- collection = this.getCollectionName(collection);
128
+ const collection = this.getCollectionName(entityName);
129
129
  const options = ctx ? { session: ctx } : {};
130
130
  if (fields) {
131
131
  options.projection = fields.reduce((o, k) => Object.assign(o, { [k]: 1 }), {});
132
132
  }
133
- const resultSet = this.getCollection(collection).find(where, options);
133
+ const resultSet = this.getCollection(entityName).find(where, options);
134
134
  let query = `db.getCollection('${collection}').find(${this.logObject(where)}, ${this.logObject(options)})`;
135
135
  orderBy = Utils.asArray(orderBy);
136
136
  if (Array.isArray(orderBy) && orderBy.length > 0) {
@@ -156,44 +156,44 @@ export class MongoConnection extends Connection {
156
156
  }
157
157
  return { cursor: resultSet, query };
158
158
  }
159
- async insertOne(collection, data, ctx) {
160
- return this.runQuery('insertOne', collection, data, undefined, ctx);
159
+ async insertOne(entityName, data, ctx) {
160
+ return this.runQuery('insertOne', entityName, data, undefined, ctx);
161
161
  }
162
- async insertMany(collection, data, ctx) {
163
- return this.runQuery('insertMany', collection, data, undefined, ctx);
162
+ async insertMany(entityName, data, ctx) {
163
+ return this.runQuery('insertMany', entityName, data, undefined, ctx);
164
164
  }
165
- async updateMany(collection, where, data, ctx, upsert, upsertOptions) {
166
- return this.runQuery('updateMany', collection, data, where, ctx, upsert, upsertOptions);
165
+ async updateMany(entityName, where, data, ctx, upsert, upsertOptions) {
166
+ return this.runQuery('updateMany', entityName, data, where, ctx, upsert, upsertOptions);
167
167
  }
168
- async bulkUpdateMany(collection, where, data, ctx, upsert, upsertOptions) {
169
- return this.runQuery('bulkUpdateMany', collection, data, where, ctx, upsert, upsertOptions);
168
+ async bulkUpdateMany(entityName, where, data, ctx, upsert, upsertOptions) {
169
+ return this.runQuery('bulkUpdateMany', entityName, data, where, ctx, upsert, upsertOptions);
170
170
  }
171
- async deleteMany(collection, where, ctx) {
172
- return this.runQuery('deleteMany', collection, undefined, where, ctx);
171
+ async deleteMany(entityName, where, ctx) {
172
+ return this.runQuery('deleteMany', entityName, undefined, where, ctx);
173
173
  }
174
- async aggregate(collection, pipeline, ctx, loggerContext) {
174
+ async aggregate(entityName, pipeline, ctx, loggerContext) {
175
175
  await this.ensureConnection();
176
- collection = this.getCollectionName(collection);
176
+ const collection = this.getCollectionName(entityName);
177
177
  /* v8 ignore next */
178
178
  const options = ctx ? { session: ctx } : {};
179
179
  const query = `db.getCollection('${collection}').aggregate(${this.logObject(pipeline)}, ${this.logObject(options)}).toArray();`;
180
180
  const now = Date.now();
181
- const res = await this.getCollection(collection).aggregate(pipeline, options).toArray();
181
+ const res = await this.getCollection(entityName).aggregate(pipeline, options).toArray();
182
182
  this.logQuery(query, { took: Date.now() - now, results: res.length, ...loggerContext });
183
183
  return res;
184
184
  }
185
- async *streamAggregate(collection, pipeline, ctx, loggerContext, stream = false) {
185
+ async *streamAggregate(entityName, pipeline, ctx, loggerContext, stream = false) {
186
186
  await this.ensureConnection();
187
- collection = this.getCollectionName(collection);
187
+ const collection = this.getCollectionName(entityName);
188
188
  /* v8 ignore next */
189
189
  const options = ctx ? { session: ctx } : {};
190
190
  const query = `db.getCollection('${collection}').aggregate(${this.logObject(pipeline)}, ${this.logObject(options)})};`;
191
- const cursor = this.getCollection(collection).aggregate(pipeline, options);
191
+ const cursor = this.getCollection(entityName).aggregate(pipeline, options);
192
192
  this.logQuery(query, { ...loggerContext });
193
193
  yield* cursor;
194
194
  }
195
- async countDocuments(collection, where, ctx) {
196
- return this.runQuery('countDocuments', collection, undefined, where, ctx);
195
+ async countDocuments(entityName, where, ctx) {
196
+ return this.runQuery('countDocuments', entityName, undefined, where, ctx);
197
197
  }
198
198
  async transactional(cb, options = {}) {
199
199
  await this.ensureConnection();
@@ -237,9 +237,9 @@ export class MongoConnection extends Connection {
237
237
  this.logQuery('db.rollback();');
238
238
  await eventBroadcaster?.dispatchEvent(EventType.afterTransactionRollback, ctx);
239
239
  }
240
- async runQuery(method, collection, data, where, ctx, upsert, upsertOptions, loggerContext) {
240
+ async runQuery(method, entityName, data, where, ctx, upsert, upsertOptions, loggerContext) {
241
241
  await this.ensureConnection();
242
- collection = this.getCollectionName(collection);
242
+ const collection = this.getCollectionName(entityName);
243
243
  const logger = this.config.getLogger();
244
244
  const options = ctx ? { session: ctx, upsert } : { upsert };
245
245
  if (options.upsert === undefined) {
@@ -253,22 +253,22 @@ export class MongoConnection extends Connection {
253
253
  case 'insertOne':
254
254
  Object.keys(data).filter(k => typeof data[k] === 'undefined').forEach(k => delete data[k]);
255
255
  query = log(() => `db.getCollection('${collection}').insertOne(${this.logObject(data)}, ${this.logObject(options)});`);
256
- res = await this.rethrow(this.getCollection(collection).insertOne(data, options), query);
256
+ res = await this.rethrow(this.getCollection(entityName).insertOne(data, options), query);
257
257
  break;
258
258
  case 'insertMany':
259
259
  data.forEach(data => Object.keys(data).filter(k => typeof data[k] === 'undefined').forEach(k => delete data[k]));
260
260
  query = log(() => `db.getCollection('${collection}').insertMany(${this.logObject(data)}, ${this.logObject(options)});`);
261
- res = await this.rethrow(this.getCollection(collection).insertMany(data, options), query);
261
+ res = await this.rethrow(this.getCollection(entityName).insertMany(data, options), query);
262
262
  break;
263
263
  case 'updateMany': {
264
- const payload = Object.keys(data).some(k => k.startsWith('$')) ? data : this.createUpdatePayload(data, upsertOptions);
264
+ const payload = Object.keys(data).every(k => k.startsWith('$')) ? data : this.createUpdatePayload(data, upsertOptions);
265
265
  query = log(() => `db.getCollection('${collection}').updateMany(${this.logObject(where)}, ${this.logObject(payload)}, ${this.logObject(options)});`);
266
- res = await this.rethrow(this.getCollection(collection).updateMany(where, payload, options), query);
266
+ res = await this.rethrow(this.getCollection(entityName).updateMany(where, payload, options), query);
267
267
  break;
268
268
  }
269
269
  case 'bulkUpdateMany': {
270
270
  query = log(() => `bulk = db.getCollection('${collection}').initializeUnorderedBulkOp(${this.logObject(options)});\n`);
271
- const bulk = this.getCollection(collection).initializeUnorderedBulkOp(options);
271
+ const bulk = this.getCollection(entityName).initializeUnorderedBulkOp(options);
272
272
  data.forEach((row, idx) => {
273
273
  const id = where[idx];
274
274
  const cond = Utils.isPlainObject(id) ? id : { _id: id };
@@ -294,7 +294,7 @@ export class MongoConnection extends Connection {
294
294
  case 'deleteMany':
295
295
  case 'countDocuments':
296
296
  query = log(() => `db.getCollection('${collection}').${method}(${this.logObject(where)}, ${this.logObject(options)});`);
297
- res = await this.rethrow(this.getCollection(collection)[method](where, options), query);
297
+ res = await this.rethrow(this.getCollection(entityName)[method](where, options), query);
298
298
  break;
299
299
  }
300
300
  this.logQuery(query, { took: Date.now() - now, ...loggerContext });
@@ -311,7 +311,14 @@ export class MongoConnection extends Connection {
311
311
  });
312
312
  }
313
313
  createUpdatePayload(row, upsertOptions) {
314
+ row = { ...row };
314
315
  const doc = { $set: row };
316
+ Utils.keys(row).forEach(k => {
317
+ if (k.toString().startsWith('$')) {
318
+ doc[k] = row[k];
319
+ delete row[k];
320
+ }
321
+ });
315
322
  const $unset = {};
316
323
  const $inc = {};
317
324
  for (const k of Utils.keys(row)) {
@@ -367,10 +374,9 @@ export class MongoConnection extends Connection {
367
374
  insertedIds: res.insertedIds ? Object.values(res.insertedIds) : undefined,
368
375
  };
369
376
  }
370
- getCollectionName(name) {
371
- name = Utils.className(name);
372
- const meta = this.metadata.find(name);
373
- return meta ? meta.collection : name;
377
+ getCollectionName(entityName) {
378
+ const meta = this.metadata.find(entityName);
379
+ return meta ? meta.collection : Utils.className(entityName);
374
380
  }
375
381
  logObject(o) {
376
382
  if (o.session) {
package/MongoDriver.d.ts CHANGED
@@ -13,25 +13,25 @@ export declare class MongoDriver extends DatabaseDriver<MongoConnection> {
13
13
  stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: StreamOptions<T, any, any, any> & {
14
14
  rawResults?: boolean;
15
15
  }): AsyncIterableIterator<T>;
16
- find<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
17
- findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
18
- findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
16
+ find<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: EntityName<T>, where: FilterQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
17
+ findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: EntityName<T>, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
18
+ findVirtual<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
19
19
  streamVirtual<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): AsyncIterableIterator<EntityData<T>>;
20
- count<T extends object>(entityName: string, where: FilterQuery<T>, options?: CountOptions<T>, ctx?: Transaction<ClientSession>): Promise<number>;
21
- nativeInsert<T extends object>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
22
- nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
23
- nativeUpdate<T extends object>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>;
24
- nativeUpdateMany<T extends object>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>;
25
- nativeDelete<T extends object>(entityName: string, where: FilterQuery<T>, options?: {
20
+ count<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options?: CountOptions<T>, ctx?: Transaction<ClientSession>): Promise<number>;
21
+ nativeInsert<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
22
+ nativeInsertMany<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
23
+ nativeUpdate<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>;
24
+ nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>;
25
+ nativeDelete<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options?: {
26
26
  ctx?: Transaction<ClientSession>;
27
27
  }): Promise<QueryResult<T>>;
28
- aggregate(entityName: string, pipeline: any[], ctx?: Transaction<ClientSession>): Promise<any[]>;
29
- streamAggregate<T extends object>(entityName: string, pipeline: any[], ctx?: Transaction<ClientSession>): AsyncIterableIterator<T>;
28
+ aggregate(entityName: EntityName, pipeline: any[], ctx?: Transaction<ClientSession>): Promise<any[]>;
29
+ streamAggregate<T extends object>(entityName: EntityName<T>, pipeline: any[], ctx?: Transaction<ClientSession>): AsyncIterableIterator<T>;
30
30
  getPlatform(): MongoPlatform;
31
31
  private renameFields;
32
32
  private convertObjectIds;
33
33
  private buildFilterById;
34
- protected buildFields<T extends object, P extends string = never>(entityName: string, populate: PopulateOptions<T>[], fields?: readonly EntityField<T, P>[], exclude?: string[]): string[] | undefined;
34
+ protected buildFields<T extends object, P extends string = never>(entityName: EntityName<T>, populate: PopulateOptions<T>[], fields?: readonly EntityField<T, P>[], exclude?: string[]): string[] | undefined;
35
35
  private handleVersionProperty;
36
36
  /** @inheritDoc */
37
37
  getORMClass(): Constructor<MongoMikroORM>;
package/MongoDriver.js CHANGED
@@ -20,7 +20,6 @@ export class MongoDriver extends DatabaseDriver {
20
20
  yield* this.streamVirtual(entityName, where, options);
21
21
  return;
22
22
  }
23
- entityName = Utils.className(entityName);
24
23
  const fields = this.buildFields(entityName, options.populate || [], options.fields, options.exclude);
25
24
  where = this.renameFields(entityName, where, true);
26
25
  const orderBy = Utils.asArray(options.orderBy).map(orderBy => this.renameFields(entityName, orderBy, true));
@@ -259,14 +258,14 @@ export class MongoDriver extends DatabaseDriver {
259
258
  return;
260
259
  }
261
260
  if (prop.array && Array.isArray(copiedData[prop.name])) {
262
- copiedData[prop.name] = copiedData[prop.name].map((item) => this.renameFields(prop.type, item, dotPaths, true));
261
+ copiedData[prop.name] = copiedData[prop.name].map((item) => this.renameFields(prop.targetMeta.class, item, dotPaths, true));
263
262
  }
264
263
  else {
265
- copiedData[prop.name] = this.renameFields(prop.type, copiedData[prop.name], dotPaths, prop.object || object);
264
+ copiedData[prop.name] = this.renameFields(prop.targetMeta.class, copiedData[prop.name], dotPaths, prop.object || object);
266
265
  }
267
266
  }
268
267
  else {
269
- const meta2 = this.metadata.find(prop.type);
268
+ const meta2 = this.metadata.find(prop.targetMeta.class);
270
269
  const pk = meta2.properties[meta2.primaryKeys[0]];
271
270
  isObjectId = pk.type === 'ObjectId';
272
271
  }
@@ -308,10 +307,7 @@ export class MongoDriver extends DatabaseDriver {
308
307
  return { _id: id };
309
308
  }
310
309
  buildFields(entityName, populate, fields, exclude) {
311
- const meta = this.metadata.find(entityName);
312
- if (!meta) {
313
- return fields;
314
- }
310
+ const meta = this.metadata.get(entityName);
315
311
  const lazyProps = meta.props.filter(prop => prop.lazy && !populate.some(p => this.isPopulated(meta, prop, p)));
316
312
  const ret = [];
317
313
  if (fields) {
@@ -9,11 +9,11 @@ export declare class MongoEntityManager<Driver extends MongoDriver = MongoDriver
9
9
  /**
10
10
  * Shortcut to driver's aggregate method. Available in MongoDriver only.
11
11
  */
12
- aggregate(entityName: EntityName<any>, pipeline: any[]): Promise<any[]>;
12
+ aggregate(entityName: EntityName, pipeline: any[]): Promise<any[]>;
13
13
  /**
14
14
  * Shortcut to driver's aggregate method. Returns a stream. Available in MongoDriver only.
15
15
  */
16
- streamAggregate<T extends object>(entityName: EntityName<any>, pipeline: any[]): AsyncIterableIterator<T>;
16
+ streamAggregate<T extends object>(entityName: EntityName, pipeline: any[]): AsyncIterableIterator<T>;
17
17
  /**
18
18
  * @inheritDoc
19
19
  */
@@ -7,14 +7,12 @@ 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
- entityName = Utils.className(entityName);
11
10
  return this.getDriver().aggregate(entityName, pipeline, this.getTransactionContext());
12
11
  }
13
12
  /**
14
13
  * Shortcut to driver's aggregate method. Returns a stream. Available in MongoDriver only.
15
14
  */
16
15
  async *streamAggregate(entityName, pipeline) {
17
- entityName = Utils.className(entityName);
18
16
  yield* this.getDriver().streamAggregate(entityName, pipeline, this.getTransactionContext());
19
17
  }
20
18
  /**
@@ -11,7 +11,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
11
11
  /* v8 ignore next */
12
12
  const promises = metadata
13
13
  .filter(meta => !existing.includes(meta.collection))
14
- .map(meta => this.connection.createCollection(meta.collection).catch(err => {
14
+ .map(meta => this.connection.createCollection(meta.class).catch(err => {
15
15
  const existsErrorMessage = `Collection ${this.config.get('dbName')}.${meta.collection} already exists.`;
16
16
  // ignore errors about the collection already existing
17
17
  if (!(err.name === 'MongoServerError' && err.message.includes(existsErrorMessage))) {
@@ -32,7 +32,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
32
32
  }
33
33
  const promises = metadata
34
34
  .filter(meta => existing.includes(meta.collection))
35
- .map(meta => this.connection.dropCollection(meta.collection));
35
+ .map(meta => this.connection.dropCollection(meta.class));
36
36
  await Promise.all(promises);
37
37
  }
38
38
  async update(options = {}) {
@@ -127,7 +127,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
127
127
  meta.indexes.forEach(index => {
128
128
  let fieldOrSpec;
129
129
  const properties = this.mapIndexProperties(index, meta);
130
- const collection = this.connection.getCollection(meta.className);
130
+ const collection = this.connection.getCollection(meta.class);
131
131
  if (Array.isArray(index.options) && index.options.length === 2 && properties.length === 0) {
132
132
  res.push([collection.collectionName, collection.createIndex(index.options[0], index.options[1])]);
133
133
  return;
@@ -173,7 +173,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
173
173
  meta.uniques.forEach(index => {
174
174
  const properties = this.mapIndexProperties(index, meta);
175
175
  const fieldOrSpec = properties.reduce((o, i) => { o[i] = 1; return o; }, {});
176
- const collection = this.connection.getCollection(meta.className);
176
+ const collection = this.connection.getCollection(meta.class);
177
177
  res.push([collection.collectionName, this.executeQuery(collection, 'createIndex', fieldOrSpec, {
178
178
  name: index.name,
179
179
  unique: true,
@@ -186,7 +186,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
186
186
  if (!prop[type] || !meta.collection) {
187
187
  return [];
188
188
  }
189
- const collection = this.connection.getCollection(meta.className);
189
+ const collection = this.connection.getCollection(meta.class);
190
190
  const fieldOrSpec = prop.embeddedPath
191
191
  ? prop.embeddedPath.join('.')
192
192
  : prop.fieldNames.reduce((o, i) => { o[i] = 1; return o; }, {});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikro-orm/mongodb",
3
3
  "type": "module",
4
- "version": "7.0.0-dev.114",
4
+ "version": "7.0.0-dev.116",
5
5
  "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.",
6
6
  "exports": {
7
7
  "./package.json": "./package.json",
@@ -53,9 +53,9 @@
53
53
  "mongodb": "7.0.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@mikro-orm/core": "^6.6.2"
56
+ "@mikro-orm/core": "^6.6.3"
57
57
  },
58
58
  "peerDependencies": {
59
- "@mikro-orm/core": "7.0.0-dev.114"
59
+ "@mikro-orm/core": "7.0.0-dev.116"
60
60
  }
61
61
  }