@mikro-orm/mongodb 7.2.0-dev.9 → 7.2.1-dev.0

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.
@@ -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;
@@ -1,5 +1,5 @@
1
1
  import { MongoClient, ObjectId, } from 'mongodb';
2
- import { Connection, EventType, inspect, QueryOrder, Utils, ValidationError, } from '@mikro-orm/core';
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(), direction.toUpperCase() === QueryOrder.ASC ? 1 : -1]);
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] = dir === 'ASC' || dir === 'asc' || dir === 1 ? 1 : -1;
109
+ sortSpec[key] =
110
+ typeof dir === 'string' || typeof dir === 'number' ? MongoConnection.getSortDirection(dir) : dir;
110
111
  }
111
112
  }
112
113
  pipeline.push({ $sort: sortSpec });
@@ -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;
@@ -20,6 +22,7 @@ export declare class MongoPlatform extends Platform {
20
22
  usesImplicitTransactions(): boolean;
21
23
  convertsJsonAutomatically(): boolean;
22
24
  preservesDatesInsideJson(): boolean;
25
+ supportsNullsOrdering(): boolean;
23
26
  convertJsonToDatabaseValue(value: unknown): unknown;
24
27
  convertJsonToJSValue(value: unknown, context?: TransformContext): unknown;
25
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');
@@ -55,6 +59,9 @@ export class MongoPlatform extends Platform {
55
59
  preservesDatesInsideJson() {
56
60
  return true;
57
61
  }
62
+ supportsNullsOrdering() {
63
+ return false;
64
+ }
58
65
  convertJsonToDatabaseValue(value) {
59
66
  return Utils.copy(value);
60
67
  }
package/README.md CHANGED
@@ -24,6 +24,7 @@ npm install @mikro-orm/mysql # MySQL
24
24
  npm install @mikro-orm/mariadb # MariaDB
25
25
  npm install @mikro-orm/sqlite # SQLite
26
26
  npm install @mikro-orm/libsql # libSQL / Turso
27
+ npm install @mikro-orm/sql-js # sql.js (in-memory SQLite in WASM)
27
28
  npm install @mikro-orm/mongodb # MongoDB
28
29
  npm install @mikro-orm/mssql # MS SQL Server
29
30
  npm install @mikro-orm/oracledb # Oracle
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mongodb",
3
- "version": "7.2.0-dev.9",
3
+ "version": "7.2.1-dev.0",
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.5.0"
50
+ "mongodb": "7.6.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@mikro-orm/core": "^7.1.11"
53
+ "@mikro-orm/core": "^7.2.0"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.2.0-dev.9"
56
+ "@mikro-orm/core": "7.2.1-dev.0"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"