@mikro-orm/mongodb 7.2.0-dev.18 → 7.2.0-dev.19
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 +5 -0
- package/MongoConnection.js +12 -2
- package/MongoDriver.js +2 -1
- package/MongoPlatform.d.ts +2 -0
- package/MongoPlatform.js +4 -0
- package/package.json +2 -2
package/MongoConnection.d.ts
CHANGED
|
@@ -27,6 +27,11 @@ export declare class MongoConnection extends Connection {
|
|
|
27
27
|
mapOptions(overrides: MongoClientOptions): MongoClientOptions;
|
|
28
28
|
getDb(): Db;
|
|
29
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;
|
|
30
35
|
find<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, opts?: MongoFindOptions<T>): Promise<EntityData<T>[]>;
|
|
31
36
|
stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, opts?: MongoFindOptions<T>): AsyncIterableIterator<T>;
|
|
32
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;
|
|
@@ -117,6 +117,16 @@ export class MongoConnection extends Connection {
|
|
|
117
117
|
async execute(query) {
|
|
118
118
|
throw new Error(`${this.constructor.name} does not support generic execute method`);
|
|
119
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
|
+
}
|
|
120
130
|
async find(entityName, where, opts = {}) {
|
|
121
131
|
const { cursor, query } = await this._find(entityName, where, opts);
|
|
122
132
|
const now = Date.now();
|
|
@@ -163,7 +173,7 @@ export class MongoConnection extends Connection {
|
|
|
163
173
|
Utils.keys(o).forEach(k => {
|
|
164
174
|
const direction = o[k];
|
|
165
175
|
if (typeof direction === 'string') {
|
|
166
|
-
orderByTuples.push([k.toString(),
|
|
176
|
+
orderByTuples.push([k.toString(), MongoConnection.getSortDirection(direction)]);
|
|
167
177
|
}
|
|
168
178
|
else {
|
|
169
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/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;
|
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');
|
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.19",
|
|
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.1.15"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.0-dev.19"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|