Skip to content

Commit 11ae61f

Browse files
committed
Merge branch 'master' into 8.0
2 parents d5e9176 + 2acc3f5 commit 11ae61f

File tree

21 files changed

+268
-34
lines changed

21 files changed

+268
-34
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ module.exports = {
1313
'*.min.js',
1414
'**/docs/js/native.js',
1515
'!.*',
16-
'node_modules'
16+
'node_modules',
17+
'.git'
1718
],
1819
overrides: [
1920
{

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
7.5.3 / 2023-09-25
2+
==================
3+
* fix(document): handle MongoDB Long when casting BigInts #13869 #13791
4+
* fix(model): make bulkSave() persist changes that happen in pre('save') middleware #13885 #13799
5+
* fix: handle casting $elemMatch underneath $not underneath another $elemMatch #13893 #13880
6+
* fix(model): make bulkWrite casting respect global setDefaultsOnInsert #13870 #13823
7+
* fix(document): handle default values for discriminator key with embedded discriminators #13891 #13835
8+
* fix: account for null values when assigning isNew property within document array #13883
9+
* types: avoid "interface can only extend object types with statically known members" error in TypeScript 4 #13871
10+
* docs(deprecations): fix typo in includeResultMetadata deprecation docs #13884 #13844
11+
* docs: fix pre element overflow in home page #13868 [ghoshRitesh12](https://github.com/ghoshRitesh12)
12+
13+
7.5.2 / 2023-09-15
14+
==================
15+
* fix(schema): handle number discriminator keys when using Schema.prototype.discriminator() #13858 #13788
16+
* fix: ignore `id` property when calling `set()` with both `id` and `_id` specified to avoid `id` setter overwriting #13762
17+
* types: pass correct document type to required and default function #13851 #13797
18+
* docs(model): add examples of using diffIndexes() to syncIndexes()and diffIndexes() api docs #13850 #13771
19+
120
7.5.1 / 2023-09-11
221
==================
322
* fix: set default value for _update when no update object is provided and versionKey is set to false #13795 #13783 [MohOraby](https://github.com/MohOraby)

docs/css/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pre {
4646
background: #eee;
4747
padding: 5px;
4848
border-radius: 3px;
49+
overflow-x: auto;
4950
}
5051
code {
5152
color: #333;

docs/deprecations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cause any problems for your application. Please [report any issues on GitHub](ht
99

1010
To fix all deprecation warnings, follow the below steps:
1111

12-
* Replace `rawResult: true` with `includeResultMetadata: false` in `findOneAndUpdate()`, `findOneAndReplace()`, `findOneAndDelete()` calls.
12+
* Replace `rawResult: true` with `includeResultMetadata: true` in `findOneAndUpdate()`, `findOneAndReplace()`, `findOneAndDelete()` calls.
1313

1414
Read below for more a more detailed description of each deprecation warning.
1515

lib/cast.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,21 @@ module.exports = function cast(schema, obj, options, context) {
309309
while (k--) {
310310
$cond = ks[k];
311311
nested = val[$cond];
312-
313-
if ($cond === '$not') {
312+
if ($cond === '$elemMatch') {
313+
if (nested && schematype != null && schematype.schema != null) {
314+
cast(schematype.schema, nested, options, context);
315+
} else if (nested && schematype != null && schematype.$isMongooseArray) {
316+
if (utils.isPOJO(nested) && nested.$not != null) {
317+
cast(schema, nested, options, context);
318+
} else {
319+
val[$cond] = schematype.castForQuery(
320+
$cond,
321+
nested,
322+
context
323+
);
324+
}
325+
}
326+
} else if ($cond === '$not') {
314327
if (nested && schematype) {
315328
_keys = Object.keys(nested);
316329
if (_keys.length && isOperator(_keys[0])) {
@@ -337,6 +350,7 @@ module.exports = function cast(schema, obj, options, context) {
337350
context
338351
);
339352
}
353+
340354
}
341355
}
342356
} else if (Array.isArray(val) && ['Buffer', 'Array'].indexOf(schematype.instance) === -1) {

lib/cast/bigint.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const assert = require('assert');
4+
const { Long } = require('bson');
45

56
/**
67
* Given a value, cast it to a BigInt, or throw an `Error` if the value
@@ -23,6 +24,10 @@ module.exports = function castBigInt(val) {
2324
return val;
2425
}
2526

27+
if (val instanceof Long) {
28+
return val.toBigInt();
29+
}
30+
2631
if (typeof val === 'string' || typeof val === 'number') {
2732
return BigInt(val);
2833
}

lib/document.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,11 @@ Document.prototype.$__set = function(pathToMark, path, options, constructing, pa
16671667
val[arrayAtomicsSymbol] = priorVal[arrayAtomicsSymbol];
16681668
val[arrayAtomicsBackupSymbol] = priorVal[arrayAtomicsBackupSymbol];
16691669
if (utils.isMongooseDocumentArray(val)) {
1670-
val.forEach(doc => { doc.isNew = false; });
1670+
val.forEach(doc => {
1671+
if (doc != null) {
1672+
doc.$isNew = false;
1673+
}
1674+
});
16711675
}
16721676
}
16731677

lib/drivers/node-mongodb-native/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ function _setClient(conn, client, options, dbName) {
349349
client.s.options.hosts &&
350350
client.s.options.hosts[0] &&
351351
client.s.options.hosts[0].port || void 0;
352-
conn.name = dbName != null ? dbName : client && client.s && client.s.options && client.s.options.dbName || void 0;
352+
conn.name = dbName != null ? dbName : db.databaseName;
353353
conn._closeCalled = client._closeCalled;
354354

355355
const _handleReconnect = () => {

lib/helpers/discriminator/getConstructor.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ const getDiscriminatorByValue = require('./getDiscriminatorByValue');
77
* @api private
88
*/
99

10-
module.exports = function getConstructor(Constructor, value) {
10+
module.exports = function getConstructor(Constructor, value, defaultDiscriminatorValue) {
1111
const discriminatorKey = Constructor.schema.options.discriminatorKey;
12-
if (value != null &&
13-
Constructor.discriminators &&
14-
value[discriminatorKey] != null) {
15-
if (Constructor.discriminators[value[discriminatorKey]]) {
16-
Constructor = Constructor.discriminators[value[discriminatorKey]];
12+
let discriminatorValue = (value != null && value[discriminatorKey]);
13+
if (discriminatorValue == null) {
14+
discriminatorValue = defaultDiscriminatorValue;
15+
}
16+
if (Constructor.discriminators &&
17+
discriminatorValue != null) {
18+
if (Constructor.discriminators[discriminatorValue]) {
19+
Constructor = Constructor.discriminators[discriminatorValue];
1720
} else {
18-
const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, value[discriminatorKey]);
21+
const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, discriminatorValue);
1922
if (constructorByValue) {
2023
Constructor = constructorByValue;
2124
}

lib/helpers/model/castBulkWrite.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const setDefaultsOnInsert = require('../setDefaultsOnInsert');
2020

2121
module.exports = function castBulkWrite(originalModel, op, options) {
2222
const now = originalModel.base.now();
23+
24+
const globalSetDefaultsOnInsert = originalModel.base.options.setDefaultsOnInsert;
2325
if (op['insertOne']) {
2426
return (callback) => {
2527
const model = decideModelByObject(originalModel, op['insertOne']['document']);
@@ -69,7 +71,10 @@ module.exports = function castBulkWrite(originalModel, op, options) {
6971
applyTimestampsToChildren(now, op['updateOne']['update'], model.schema);
7072
}
7173

72-
if (op['updateOne'].setDefaultsOnInsert !== false) {
74+
const shouldSetDefaultsOnInsert = op['updateOne'].setDefaultsOnInsert == null ?
75+
globalSetDefaultsOnInsert :
76+
op['updateOne'].setDefaultsOnInsert;
77+
if (shouldSetDefaultsOnInsert !== false) {
7378
setDefaultsOnInsert(op['updateOne']['filter'], model.schema, op['updateOne']['update'], {
7479
setDefaultsOnInsert: true,
7580
upsert: op['updateOne'].upsert
@@ -106,7 +111,11 @@ module.exports = function castBulkWrite(originalModel, op, options) {
106111
const schema = model.schema;
107112
const strict = options.strict != null ? options.strict : model.schema.options.strict;
108113

109-
if (op['updateMany'].setDefaultsOnInsert !== false) {
114+
const shouldSetDefaultsOnInsert = op['updateMany'].setDefaultsOnInsert == null ?
115+
globalSetDefaultsOnInsert :
116+
op['updateMany'].setDefaultsOnInsert;
117+
118+
if (shouldSetDefaultsOnInsert !== false) {
110119
setDefaultsOnInsert(op['updateMany']['filter'], model.schema, op['updateMany']['update'], {
111120
setDefaultsOnInsert: true,
112121
upsert: op['updateMany'].upsert

0 commit comments

Comments
 (0)