Skip to content

Commit

Permalink
Merge branch 'master' into vkarpov15/gh-12548
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Dec 23, 2022
2 parents a4bd7cc + 2fd0d29 commit 1c6cb93
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/search.js
Expand Up @@ -122,13 +122,13 @@ async function run() {
await Content.deleteMany({ version });
for (const content of contents) {
if (version !== '6.x') {
content.url = `/docs/${version}/docs/${content.url}`;
content.url = `/docs/${version}/docs${content.url}`;
}
await content.save();
}

const results = await Content.
find({ $text: { $search: 'validate' } }, { score: { $meta: 'textScore' } }).
find({ $text: { $search: 'validate' }, version }, { score: { $meta: 'textScore' } }).
sort({ score: { $meta: 'textScore' } }).
limit(10);

Expand Down
8 changes: 5 additions & 3 deletions lib/helpers/query/castUpdate.js
Expand Up @@ -85,9 +85,11 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
val = ret[op];
hasDollarKey = hasDollarKey || op.startsWith('$');
const toUnset = {};
for (const key of Object.keys(val)) {
if (val[key] === undefined) {
toUnset[key] = 1;
if (val != null) {
for (const key of Object.keys(val)) {
if (val[key] === undefined) {
toUnset[key] = 1;
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion test/query.test.js
Expand Up @@ -4314,7 +4314,7 @@ describe('Query', function() {
assert.strictEqual(found[0].title, 'burrito bowl');
});

it('update operation should remove fields set to undefined (gh-12794)', async() => {
it('update operation should remove fields set to undefined (gh-12794) (gh-12821)', async function() {
const m = new mongoose.Mongoose();

await m.connect(start.uri);
Expand All @@ -4338,5 +4338,15 @@ describe('Query', function() {
).lean();

assert.ok('title' in updatedDoc === false);

const replacedDoc = await Test.findOneAndReplace(
{
_id: doc._id
},
{ title: undefined },
{ returnOriginal: false }
).lean();

assert.ok('title' in replacedDoc === false);
});
});
2 changes: 1 addition & 1 deletion test/schema.test.js
Expand Up @@ -2833,7 +2833,7 @@ describe('schema', function() {
assert.equal(entry instanceof mongoose.Document, false);
});

it('disallows setting special properties with `add()` or constructor (gh-12085)', async function() {
it('disallows setting special properties with `add()` or constructor (gh-12085)', function() {
const maliciousPayload = '{"__proto__.toString": "Number"}';

assert.throws(() => {
Expand Down

0 comments on commit 1c6cb93

Please sign in to comment.