@mikro-orm/mongodb 6.2.10-dev.59 → 6.2.10-dev.60

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
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mongodb",
3
- "version": "6.2.10-dev.59",
3
+ "version": "6.2.10-dev.60",
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",
@@ -65,6 +65,6 @@
65
65
  "@mikro-orm/core": "^6.2.9"
66
66
  },
67
67
  "peerDependencies": {
68
- "@mikro-orm/core": "6.2.10-dev.59"
68
+ "@mikro-orm/core": "6.2.10-dev.60"
69
69
  }
70
70
  }