2024-04-07 22:18:04 -04:00
|
|
|
// @tags: [requires_non_retryable_writes]
|
2017-03-23 14:07:50 -04:00
|
|
|
|
2012-03-16 20:34:29 -07:00
|
|
|
// Check that the positional operator works properly when an index only match is used for the update
|
|
|
|
|
// query spec. SERVER-5067
|
|
|
|
|
|
2025-02-04 14:03:10 -05:00
|
|
|
const t = db[jsTestName()];
|
2012-03-16 20:34:29 -07:00
|
|
|
t.drop();
|
|
|
|
|
|
|
|
|
|
function testPositionalInc() {
|
2025-02-04 14:03:10 -05:00
|
|
|
assert.commandWorked(t.remove({}));
|
|
|
|
|
assert.commandWorked(t.save({a: [{b: 'match', count: 0}]}));
|
|
|
|
|
assert.commandWorked(t.update({'a.b': 'match'}, {$inc: {'a.$.count': 1}}));
|
2012-03-16 20:34:29 -07:00
|
|
|
// Check that the positional $inc succeeded.
|
2016-03-09 12:17:50 -05:00
|
|
|
assert(t.findOne({'a.count': 1}));
|
2012-03-16 20:34:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testPositionalInc();
|
|
|
|
|
|
|
|
|
|
// Now check with a non multikey index.
|
2025-02-04 14:03:10 -05:00
|
|
|
assert.commandWorked(t.createIndex({'a.b': 1}));
|
2012-03-16 20:34:29 -07:00
|
|
|
testPositionalInc();
|