@mikro-orm/mongodb 7.2.0-dev.2 → 7.2.0-dev.21
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 +7 -0
- package/MongoConnection.js +17 -2
- package/MongoDriver.js +2 -1
- package/MongoEntityManager.js +1 -2
- package/MongoPlatform.d.ts +4 -0
- package/MongoPlatform.js +10 -0
- package/package.json +4 -4
package/MongoConnection.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export declare class MongoConnection extends Connection {
|
|
|
18
18
|
error?: Error;
|
|
19
19
|
}>;
|
|
20
20
|
getClient(): MongoClient;
|
|
21
|
+
/** Returns the `MongoClient` backing this connection, the async counterpart of `getClient()`. */
|
|
22
|
+
getNativeClient(): Promise<MongoClient>;
|
|
21
23
|
getCollection<T extends object>(name: EntityName<T> | string): Collection<T>;
|
|
22
24
|
createCollection<T extends object>(name: EntityName<T>): Promise<Collection<T>>;
|
|
23
25
|
listCollections(): Promise<string[]>;
|
|
@@ -25,6 +27,11 @@ export declare class MongoConnection extends Connection {
|
|
|
25
27
|
mapOptions(overrides: MongoClientOptions): MongoClientOptions;
|
|
26
28
|
getDb(): Db;
|
|
27
29
|
execute(query: string): Promise<any>;
|
|
30
|
+
/**
|
|
31
|
+
* Maps an order direction to mongo's `1`/`-1`, ignoring any `nulls first`/`nulls last` qualifier, which mongo cannot honor.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
static getSortDirection(direction: string | number): 1 | -1;
|
|
28
35
|
find<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, opts?: MongoFindOptions<T>): Promise<EntityData<T>[]>;
|
|
29
36
|
stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, opts?: MongoFindOptions<T>): AsyncIterableIterator<T>;
|
|
30
37
|
private _find;
|
package/MongoConnection.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MongoClient, ObjectId, } from 'mongodb';
|
|
2
|
-
import { Connection, EventType, inspect,
|
|
2
|
+
import { Connection, EventType, inspect, QueryOrderNumeric, Utils, ValidationError, } from '@mikro-orm/core';
|
|
3
3
|
/** MongoDB database connection using the official `mongodb` driver. */
|
|
4
4
|
export class MongoConnection extends Connection {
|
|
5
5
|
#client;
|
|
@@ -76,6 +76,11 @@ export class MongoConnection extends Connection {
|
|
|
76
76
|
}
|
|
77
77
|
return this.#client;
|
|
78
78
|
}
|
|
79
|
+
/** Returns the `MongoClient` backing this connection, the async counterpart of `getClient()`. */
|
|
80
|
+
async getNativeClient() {
|
|
81
|
+
await this.ensureConnection();
|
|
82
|
+
return this.getClient();
|
|
83
|
+
}
|
|
79
84
|
getCollection(name) {
|
|
80
85
|
return this.getDb().collection(this.getCollectionName(name));
|
|
81
86
|
}
|
|
@@ -112,6 +117,16 @@ export class MongoConnection extends Connection {
|
|
|
112
117
|
async execute(query) {
|
|
113
118
|
throw new Error(`${this.constructor.name} does not support generic execute method`);
|
|
114
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Maps an order direction to mongo's `1`/`-1`, ignoring any `nulls first`/`nulls last` qualifier, which mongo cannot honor.
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
static getSortDirection(direction) {
|
|
125
|
+
if (typeof direction === 'number') {
|
|
126
|
+
return direction === QueryOrderNumeric.DESC ? -1 : 1;
|
|
127
|
+
}
|
|
128
|
+
return direction.toLowerCase().startsWith('desc') ? -1 : 1;
|
|
129
|
+
}
|
|
115
130
|
async find(entityName, where, opts = {}) {
|
|
116
131
|
const { cursor, query } = await this._find(entityName, where, opts);
|
|
117
132
|
const now = Date.now();
|
|
@@ -158,7 +173,7 @@ export class MongoConnection extends Connection {
|
|
|
158
173
|
Utils.keys(o).forEach(k => {
|
|
159
174
|
const direction = o[k];
|
|
160
175
|
if (typeof direction === 'string') {
|
|
161
|
-
orderByTuples.push([k.toString(),
|
|
176
|
+
orderByTuples.push([k.toString(), MongoConnection.getSortDirection(direction)]);
|
|
162
177
|
}
|
|
163
178
|
else {
|
|
164
179
|
orderByTuples.push([k.toString(), direction]);
|
package/MongoDriver.js
CHANGED
|
@@ -106,7 +106,8 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
106
106
|
const sortSpec = {};
|
|
107
107
|
for (const order of orderBy) {
|
|
108
108
|
for (const [key, dir] of Object.entries(order)) {
|
|
109
|
-
sortSpec[key] =
|
|
109
|
+
sortSpec[key] =
|
|
110
|
+
typeof dir === 'string' || typeof dir === 'number' ? MongoConnection.getSortDirection(dir) : dir;
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
pipeline.push({ $sort: sortSpec });
|
package/MongoEntityManager.js
CHANGED
|
@@ -32,8 +32,7 @@ export class MongoEntityManager extends EntityManager {
|
|
|
32
32
|
*/
|
|
33
33
|
async countBy(entityName, groupBy, options = {}) {
|
|
34
34
|
const em = this.getContext(false);
|
|
35
|
-
options =
|
|
36
|
-
em.prepareOptions(options);
|
|
35
|
+
options = em.prepareOptions(options);
|
|
37
36
|
const meta = em.getMetadata().find(entityName);
|
|
38
37
|
const fields = Utils.asArray(groupBy);
|
|
39
38
|
if (options.having) {
|
package/MongoPlatform.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { MongoSchemaGenerator } from './MongoSchemaGenerator.js';
|
|
|
5
5
|
/** Platform implementation for MongoDB. */
|
|
6
6
|
export declare class MongoPlatform extends Platform {
|
|
7
7
|
protected readonly exceptionConverter: MongoExceptionConverter;
|
|
8
|
+
/** Mongo always sorts null and missing values lowest, and cannot be asked for anything else. */
|
|
9
|
+
sortsNullsLowest(): boolean;
|
|
8
10
|
setConfig(config: Configuration): void;
|
|
9
11
|
getNamingStrategy(): {
|
|
10
12
|
new (): NamingStrategy;
|
|
@@ -19,6 +21,8 @@ export declare class MongoPlatform extends Platform {
|
|
|
19
21
|
denormalizePrimaryKey(data: number | string): IPrimaryKey;
|
|
20
22
|
usesImplicitTransactions(): boolean;
|
|
21
23
|
convertsJsonAutomatically(): boolean;
|
|
24
|
+
preservesDatesInsideJson(): boolean;
|
|
25
|
+
supportsNullsOrdering(): boolean;
|
|
22
26
|
convertJsonToDatabaseValue(value: unknown): unknown;
|
|
23
27
|
convertJsonToJSValue(value: unknown, context?: TransformContext): unknown;
|
|
24
28
|
marshallArray(values: string[]): string;
|
package/MongoPlatform.js
CHANGED
|
@@ -6,6 +6,10 @@ import { MongoSchemaGenerator } from './MongoSchemaGenerator.js';
|
|
|
6
6
|
/** Platform implementation for MongoDB. */
|
|
7
7
|
export class MongoPlatform extends Platform {
|
|
8
8
|
exceptionConverter = new MongoExceptionConverter();
|
|
9
|
+
/** Mongo always sorts null and missing values lowest, and cannot be asked for anything else. */
|
|
10
|
+
sortsNullsLowest() {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
9
13
|
setConfig(config) {
|
|
10
14
|
config.set('autoJoinOneToOneOwner', false);
|
|
11
15
|
config.set('loadStrategy', 'select-in');
|
|
@@ -52,6 +56,12 @@ export class MongoPlatform extends Platform {
|
|
|
52
56
|
convertsJsonAutomatically() {
|
|
53
57
|
return true;
|
|
54
58
|
}
|
|
59
|
+
preservesDatesInsideJson() {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
supportsNullsOrdering() {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
55
65
|
convertJsonToDatabaseValue(value) {
|
|
56
66
|
return Utils.copy(value);
|
|
57
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mongodb",
|
|
3
|
-
"version": "7.2.0-dev.
|
|
3
|
+
"version": "7.2.0-dev.21",
|
|
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",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"mongodb": "7.
|
|
50
|
+
"mongodb": "7.6.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@mikro-orm/core": "^7.1.
|
|
53
|
+
"@mikro-orm/core": "^7.1.15"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.0-dev.21"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|