@mikro-orm/mongodb 7.2.8-dev.4 → 7.2.8-dev.6

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/MongoDriver.d.ts CHANGED
@@ -35,6 +35,7 @@ export declare class MongoDriver extends DatabaseDriver<MongoConnection> {
35
35
  private buildQueryOptions;
36
36
  /** @internal */
37
37
  renameFields<T extends object>(entityName: EntityName<T>, data: T, dotPaths?: boolean, object?: boolean, root?: boolean): T;
38
+ private convertRegExpOperator;
38
39
  private convertObjectIds;
39
40
  private buildFilterById;
40
41
  protected buildFields<T extends object, P extends string = never>(entityName: EntityName<T>, populate: PopulateOptions<T>[], fields?: readonly EntityField<T, P>[], exclude?: string[]): string[] | undefined;
package/MongoDriver.js CHANGED
@@ -392,6 +392,7 @@ export class MongoDriver extends DatabaseDriver {
392
392
  }
393
393
  return;
394
394
  }
395
+ let key = k;
395
396
  if (meta?.properties[k]) {
396
397
  const prop = meta.properties[k];
397
398
  let isObjectId = false;
@@ -455,14 +456,25 @@ export class MongoDriver extends DatabaseDriver {
455
456
  }
456
457
  if (prop.fieldNames) {
457
458
  Utils.renameKey(copiedData, k, prop.fieldNames[0]);
459
+ key = prop.fieldNames[0];
458
460
  }
459
461
  }
460
- if (Utils.isPlainObject(copiedData[k]) && '$re' in copiedData[k]) {
461
- copiedData[k] = new RegExp(copiedData[k].$re);
462
- }
462
+ copiedData[key] = this.convertRegExpOperator(copiedData[key]);
463
463
  });
464
464
  return copiedData;
465
465
  }
466
+ convertRegExpOperator(value) {
467
+ if (!Utils.isPlainObject(value)) {
468
+ return value;
469
+ }
470
+ const cond = '$not' in value ? { ...value, $not: this.convertRegExpOperator(value.$not) } : value;
471
+ if (!('$re' in cond)) {
472
+ return cond;
473
+ }
474
+ const { $re, ...rest } = cond;
475
+ // mongo has no `$re`: a RegExp when it stands alone, `$regex` next to other operators
476
+ return Utils.hasObjectKeys(rest) ? { ...rest, $regex: $re } : new RegExp($re);
477
+ }
466
478
  convertObjectIds(data) {
467
479
  if (data instanceof ObjectId) {
468
480
  return data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mongodb",
3
- "version": "7.2.8-dev.4",
3
+ "version": "7.2.8-dev.6",
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.2.7"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.2.8-dev.4"
56
+ "@mikro-orm/core": "7.2.8-dev.6"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"