Files
mongo/jstests/core/query/update/update_arraymatch7.js
Mihai Andrei 5ed8f7dcf5 SERVER-93427 Move query writing tests from jstests/core/write to jstests/core/query (#31702)
GitOrigin-RevId: 2d69ca12e591fda58c4a5387ffae9d97c0ef2283
2025-02-04 19:38:51 +00:00

22 lines
651 B
JavaScript

// @tags: [requires_non_retryable_writes]
// Check that the positional operator works properly when an index only match is used for the update
// query spec. SERVER-5067
const t = db[jsTestName()];
t.drop();
function testPositionalInc() {
assert.commandWorked(t.remove({}));
assert.commandWorked(t.save({a: [{b: 'match', count: 0}]}));
assert.commandWorked(t.update({'a.b': 'match'}, {$inc: {'a.$.count': 1}}));
// Check that the positional $inc succeeded.
assert(t.findOne({'a.count': 1}));
}
testPositionalInc();
// Now check with a non multikey index.
assert.commandWorked(t.createIndex({'a.b': 1}));
testPositionalInc();