@mikro-orm/mongodb 6.2.10-dev.9 → 6.2.10-dev.91

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.
@@ -249,8 +249,14 @@ class MongoConnection extends core_1.Connection {
249
249
  const cond = core_1.Utils.isPlainObject(id) ? id : { _id: id };
250
250
  const doc = this.createUpdatePayload(row, upsertOptions);
251
251
  if (upsert) {
252
- query += log(() => `bulk.find(${this.logObject(cond)}).upsert().update(${this.logObject(doc)});\n`);
253
- bulk.find(cond).upsert().update(doc);
252
+ if (core_1.Utils.isEmpty(cond)) {
253
+ query += log(() => `bulk.insert(${this.logObject(row)});\n`);
254
+ bulk.insert(row);
255
+ }
256
+ else {
257
+ query += log(() => `bulk.find(${this.logObject(cond)}).upsert().update(${this.logObject(doc)});\n`);
258
+ bulk.find(cond).upsert().update(doc);
259
+ }
254
260
  return;
255
261
  }
256
262
  query += log(() => `bulk.find(${this.logObject(cond)}).update(${this.logObject(doc)});\n`);
package/MongoDriver.js CHANGED
@@ -104,7 +104,7 @@ class MongoDriver extends core_1.DatabaseDriver {
104
104
  const meta = this.metadata.find(entityName);
105
105
  /* istanbul ignore next */
106
106
  const rename = (field) => meta ? (meta.properties[field]?.fieldNames[0] ?? field) : field;
107
- if (options.onConflictFields) {
107
+ if (options.onConflictFields && Array.isArray(options.onConflictFields)) {
108
108
  options.onConflictFields = options.onConflictFields.map(rename);
109
109
  }
110
110
  if (options.onConflictMergeFields) {
@@ -127,7 +127,7 @@ class MongoDriver extends core_1.DatabaseDriver {
127
127
  const meta = this.metadata.find(entityName);
128
128
  /* istanbul ignore next */
129
129
  const rename = (field) => meta ? (meta.properties[field]?.fieldNames[0] ?? field) : field;
130
- if (options.onConflictFields) {
130
+ if (options.onConflictFields && Array.isArray(options.onConflictFields)) {
131
131
  options.onConflictFields = options.onConflictFields.map(rename);
132
132
  }
133
133
  if (options.onConflictMergeFields) {
@@ -136,7 +136,19 @@ class MongoDriver extends core_1.DatabaseDriver {
136
136
  if (options.onConflictExcludeFields) {
137
137
  options.onConflictExcludeFields = options.onConflictExcludeFields.map(rename);
138
138
  }
139
- return this.rethrow(this.getConnection('write').bulkUpdateMany(entityName, where, data, options.ctx, options.upsert, options));
139
+ /* istanbul ignore next */
140
+ const pk = meta?.getPrimaryProps()[0].fieldNames[0] ?? '_id';
141
+ const res = await this.rethrow(this.getConnection('write').bulkUpdateMany(entityName, where, data, options.ctx, options.upsert, options));
142
+ if (res.insertedIds) {
143
+ let i = 0;
144
+ res.rows = where.map(cond => {
145
+ if (core_1.Utils.isEmpty(cond)) {
146
+ return { [pk]: res.insertedIds[i++] };
147
+ }
148
+ return { [pk]: cond[pk] };
149
+ });
150
+ }
151
+ return res;
140
152
  }
141
153
  async nativeDelete(entityName, where, options = {}) {
142
154
  if (core_1.Utils.isPrimaryKey(where)) {
package/MongoMikroORM.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineMongoConfig = exports.MongoMikroORM = void 0;
3
+ exports.MongoMikroORM = void 0;
4
+ exports.defineMongoConfig = defineMongoConfig;
4
5
  const core_1 = require("@mikro-orm/core");
5
6
  const MongoDriver_1 = require("./MongoDriver");
6
7
  /**
@@ -26,4 +27,3 @@ exports.MongoMikroORM = MongoMikroORM;
26
27
  function defineMongoConfig(options) {
27
28
  return (0, core_1.defineConfig)({ driver: MongoDriver_1.MongoDriver, ...options });
28
29
  }
29
- exports.defineMongoConfig = defineMongoConfig;
@@ -21,7 +21,7 @@ export declare class MongoPlatform extends Platform {
21
21
  usesImplicitTransactions(): boolean;
22
22
  convertsJsonAutomatically(): boolean;
23
23
  convertJsonToDatabaseValue(value: unknown): unknown;
24
- convertJsonToJSValue(value: unknown): unknown;
24
+ convertJsonToJSValue(value: unknown, prop: EntityProperty): unknown;
25
25
  marshallArray(values: string[]): string;
26
26
  cloneEmbeddable<T>(data: T): T;
27
27
  shouldHaveColumn<T>(prop: EntityProperty<T>, populate: PopulateOptions<T>[], exclude?: string[]): boolean;
package/MongoPlatform.js CHANGED
@@ -63,7 +63,7 @@ class MongoPlatform extends core_1.Platform {
63
63
  convertJsonToDatabaseValue(value) {
64
64
  return core_1.Utils.copy(value);
65
65
  }
66
- convertJsonToJSValue(value) {
66
+ convertJsonToJSValue(value, prop) {
67
67
  return value;
68
68
  }
69
69
  marshallArray(values) {
package/index.mjs CHANGED
@@ -25,6 +25,7 @@ export const ChangeSet = mod.ChangeSet;
25
25
  export const ChangeSetComputer = mod.ChangeSetComputer;
26
26
  export const ChangeSetPersister = mod.ChangeSetPersister;
27
27
  export const ChangeSetType = mod.ChangeSetType;
28
+ export const CharacterType = mod.CharacterType;
28
29
  export const Check = mod.Check;
29
30
  export const CheckConstraintViolationException = mod.CheckConstraintViolationException;
30
31
  export const Collection = mod.Collection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mongodb",
3
- "version": "6.2.10-dev.9",
3
+ "version": "6.2.10-dev.91",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -59,12 +59,12 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "bson": "^6.7.0",
62
- "mongodb": "6.7.0"
62
+ "mongodb": "6.8.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@mikro-orm/core": "^6.2.9"
66
66
  },
67
67
  "peerDependencies": {
68
- "@mikro-orm/core": "6.2.10-dev.9"
68
+ "@mikro-orm/core": "6.2.10-dev.91"
69
69
  }
70
70
  }