summaryrefslogtreecommitdiff
path: root/jstests/core/commands_that_do_not_write_do_not_accept_wc.js
blob: bcd2143340fd9a4cf1f5b12882e128b4cb4092f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
 * This file tests commands that do not support write concern. It passes both valid and invalid
 * writeConcern fields to commands and expects the commands to fail with a writeConcernNotSupported
 * error.
 *
 * The test runs commands that are not allowed with security token: mapReduce.
 * @tags: [
 *   not_allowed_with_security_token,
 *   assumes_write_concern_unchanged,
 *   does_not_support_stepdowns,
 * ]
 */

(function() {
"use strict";
var collName = 'leaves';

var commands = [];

commands.push({find: collName, query: {_id: 1}});

commands.push({distinct: collName, key: "_id"});

commands.push({count: collName, query: {type: 'oak'}});

commands.push({
    mapReduce: collName,
    map: function() {
        this.tags.forEach(function(z) {
            emit(z, 1);
        });
    },
    reduce: function(key, values) {
        return {count: values.length};
    },
    out: {inline: 1}
});

function assertWriteConcernNotSupportedError(res) {
    assert.commandFailed(res);
    assert.eq(res.code, ErrorCodes.InvalidOptions);
    assert(!res.writeConcernError);
}

// Test a variety of valid and invalid writeConcerns to confirm that they still all get
// the correct error.
var writeConcerns = [{w: 'invalid'}, {w: 1}];

function testUnsupportedWriteConcern(wc, cmd) {
    cmd.writeConcern = wc;
    jsTest.log("Testing " + tojson(cmd));

    var res = db.runCommand(cmd);
    assertWriteConcernNotSupportedError(res);
}

// Verify that each command gets a writeConcernNotSupported error.
commands.forEach(function(cmd) {
    writeConcerns.forEach(function(wc) {
        testUnsupportedWriteConcern(wc, cmd);
    });
});
})();