@mikro-orm/mongodb 7.2.8-dev.6 → 7.2.8-dev.7
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 +1 -0
- package/MongoDriver.js +18 -4
- package/package.json +2 -2
package/MongoDriver.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare class MongoDriver extends DatabaseDriver<MongoConnection> {
|
|
|
36
36
|
/** @internal */
|
|
37
37
|
renameFields<T extends object>(entityName: EntityName<T>, data: T, dotPaths?: boolean, object?: boolean, root?: boolean): T;
|
|
38
38
|
private convertRegExpOperator;
|
|
39
|
+
private convertRegExpOperators;
|
|
39
40
|
private convertObjectIds;
|
|
40
41
|
private buildFilterById;
|
|
41
42
|
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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ObjectId } from 'mongodb';
|
|
2
|
-
import { DatabaseDriver, EntityManagerType, PolymorphicRef, ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
|
+
import { DatabaseDriver, EntityManagerType, GroupOperator, PolymorphicRef, ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
3
3
|
import { MongoConnection } from './MongoConnection.js';
|
|
4
4
|
import { MongoPlatform } from './MongoPlatform.js';
|
|
5
5
|
import { MongoEntityManager } from './MongoEntityManager.js';
|
|
@@ -200,7 +200,7 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
200
200
|
const meta = this.metadata.find(entityName);
|
|
201
201
|
const pk = meta.getPrimaryProps()[0].fieldNames[0] ?? '_id';
|
|
202
202
|
const normalizedWhere = Utils.isPrimaryKey(where) ? { [pk]: where } : where;
|
|
203
|
-
const renameWhere = this.renameFields(entityName, normalizedWhere);
|
|
203
|
+
const renameWhere = this.renameFields(entityName, normalizedWhere, true);
|
|
204
204
|
const source = await this.rethrow(this.getConnection('read').find(entityName, renameWhere, { ctx: options.ctx, limit: 1 }));
|
|
205
205
|
if (!source.length) {
|
|
206
206
|
throw new Error('Cannot clone: no entity found matching the given condition');
|
|
@@ -459,7 +459,10 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
459
459
|
key = prop.fieldNames[0];
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
|
-
|
|
462
|
+
// `dotPaths` marks a query, entity data (e.g. JSON values) must stay as-is
|
|
463
|
+
if (dotPaths) {
|
|
464
|
+
copiedData[key] = this.convertRegExpOperator(copiedData[key]);
|
|
465
|
+
}
|
|
463
466
|
});
|
|
464
467
|
return copiedData;
|
|
465
468
|
}
|
|
@@ -467,7 +470,10 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
467
470
|
if (!Utils.isPlainObject(value)) {
|
|
468
471
|
return value;
|
|
469
472
|
}
|
|
470
|
-
|
|
473
|
+
let cond = '$not' in value ? { ...value, $not: this.convertRegExpOperator(value.$not) } : value;
|
|
474
|
+
if (Utils.isPlainObject(cond.$elemMatch)) {
|
|
475
|
+
cond = { ...cond, $elemMatch: this.convertRegExpOperators(cond.$elemMatch) };
|
|
476
|
+
}
|
|
471
477
|
if (!('$re' in cond)) {
|
|
472
478
|
return cond;
|
|
473
479
|
}
|
|
@@ -475,6 +481,14 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
475
481
|
// mongo has no `$re`: a RegExp when it stands alone, `$regex` next to other operators
|
|
476
482
|
return Utils.hasObjectKeys(rest) ? { ...rest, $regex: $re } : new RegExp($re);
|
|
477
483
|
}
|
|
484
|
+
convertRegExpOperators(where) {
|
|
485
|
+
return Object.fromEntries(Object.entries(where).map(([k, v]) => [
|
|
486
|
+
k,
|
|
487
|
+
k in GroupOperator && Array.isArray(v)
|
|
488
|
+
? v.map(c => this.convertRegExpOperators(c))
|
|
489
|
+
: this.convertRegExpOperator(v),
|
|
490
|
+
]));
|
|
491
|
+
}
|
|
478
492
|
convertObjectIds(data) {
|
|
479
493
|
if (data instanceof ObjectId) {
|
|
480
494
|
return data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mongodb",
|
|
3
|
-
"version": "7.2.8-dev.
|
|
3
|
+
"version": "7.2.8-dev.7",
|
|
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.
|
|
56
|
+
"@mikro-orm/core": "7.2.8-dev.7"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|