@mikro-orm/mongodb 7.2.9-dev.0 → 7.2.9-dev.10
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/MongoDriver.js +3 -0
- package/MongoSchemaGenerator.js +8 -7
- package/package.json +2 -2
package/MongoDriver.js
CHANGED
|
@@ -255,6 +255,8 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
255
255
|
res.row = { _id: res.insertId };
|
|
256
256
|
return res;
|
|
257
257
|
}
|
|
258
|
+
// work on a copy, `em.upsert()` builds the entity from the caller's data and must not see the `$inc`
|
|
259
|
+
data = { ...data };
|
|
258
260
|
this.handleVersionProperty(entityName, data, true);
|
|
259
261
|
data = this.renameFields(entityName, data);
|
|
260
262
|
where = this.renameFields(entityName, where, true);
|
|
@@ -281,6 +283,7 @@ export class MongoDriver extends DatabaseDriver {
|
|
|
281
283
|
return row;
|
|
282
284
|
});
|
|
283
285
|
data = data.map(row => {
|
|
286
|
+
row = { ...row };
|
|
284
287
|
this.handleVersionProperty(entityName, row, true);
|
|
285
288
|
return this.renameFields(entityName, row);
|
|
286
289
|
});
|
package/MongoSchemaGenerator.js
CHANGED
|
@@ -138,7 +138,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
138
138
|
// The array-form escape hatch passes raw [spec, options] to the driver; fold `where`
|
|
139
139
|
// into the options dict (on a clone, to avoid mutating the user's metadata).
|
|
140
140
|
const opts = { ...index.options[1] };
|
|
141
|
-
this.applyPartialFilter(opts, index.where, index.name, meta
|
|
141
|
+
this.applyPartialFilter(opts, index.where, index.name, meta);
|
|
142
142
|
res.push([collection.collectionName, collection.createIndex(index.options[0], opts)]);
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
@@ -176,7 +176,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
176
176
|
if (index.invisible) {
|
|
177
177
|
indexOptions.hidden = true;
|
|
178
178
|
}
|
|
179
|
-
this.applyPartialFilter(indexOptions, index.where, index.name, meta
|
|
179
|
+
this.applyPartialFilter(indexOptions, index.where, index.name, meta);
|
|
180
180
|
res.push([collection.collectionName, this.executeQuery(collection, 'createIndex', fieldOrSpec, indexOptions)]);
|
|
181
181
|
});
|
|
182
182
|
return res;
|
|
@@ -185,20 +185,21 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
185
185
|
* An explicit `options.partialFilterExpression` wins over `where` — this preserves the
|
|
186
186
|
* long-standing `options: { partialFilterExpression }` escape hatch.
|
|
187
187
|
*/
|
|
188
|
-
applyPartialFilter(options, where, indexName,
|
|
188
|
+
applyPartialFilter(options, where, indexName, meta) {
|
|
189
189
|
if (where == null) {
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
192
|
if (options.partialFilterExpression != null) {
|
|
193
193
|
this.config
|
|
194
194
|
.getLogger()
|
|
195
|
-
.warn('schema', `Index '${indexName ?? '(unnamed)'}' on entity '${
|
|
195
|
+
.warn('schema', `Index '${indexName ?? '(unnamed)'}' on entity '${meta.className}': both \`where\` and \`options.partialFilterExpression\` are set; \`options.partialFilterExpression\` wins.`);
|
|
196
196
|
return;
|
|
197
197
|
}
|
|
198
198
|
if (typeof where === 'string') {
|
|
199
|
-
throw new Error(`Index '${indexName ?? '(unnamed)'}' on entity '${
|
|
199
|
+
throw new Error(`Index '${indexName ?? '(unnamed)'}' on entity '${meta.className}': string \`where\` is not supported on MongoDB; pass an object/FilterQuery (it maps to MongoDB's \`partialFilterExpression\`).`);
|
|
200
200
|
}
|
|
201
|
-
|
|
201
|
+
// map property names to field names, the same way the driver does for queries
|
|
202
|
+
options.partialFilterExpression = this.driver.renameFields(meta.class, where, true);
|
|
202
203
|
}
|
|
203
204
|
async executeQuery(collection, method, ...args) {
|
|
204
205
|
const now = Date.now();
|
|
@@ -227,7 +228,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
227
228
|
unique: true,
|
|
228
229
|
...index.options,
|
|
229
230
|
};
|
|
230
|
-
this.applyPartialFilter(indexOptions, index.where, index.name, meta
|
|
231
|
+
this.applyPartialFilter(indexOptions, index.where, index.name, meta);
|
|
231
232
|
res.push([collection.collectionName, this.executeQuery(collection, 'createIndex', fieldOrSpec, indexOptions)]);
|
|
232
233
|
});
|
|
233
234
|
return res;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mongodb",
|
|
3
|
-
"version": "7.2.9-dev.
|
|
3
|
+
"version": "7.2.9-dev.10",
|
|
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.2.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.9-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.9-dev.10"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|