summaryrefslogtreecommitdiff
path: root/jstests/readonly/write_ops.js
blob: b966b2bcb19754515a666069c4b5291f3c282620 (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
load("jstests/readonly/lib/read_only_test.js");

runReadOnlyTest(function() {
    'use strict';
    return {
        name: 'write_ops',
        load: function(writableCollection) {
            assert.commandWorked(writableCollection.insert({_id: 0, x: 1}));
        },
        exec: function(readableCollection) {
            // Refresh the cluster's collection sharding state in order to have a predictable error
            // returned from the failed writes, otherwhise MultipleErrorsOcurred might be returned
            // if any shard is stale
            readableCollection.count();
            // Test that insert fails.
            assert.writeErrorWithCode(
                readableCollection.insert({x: 2}),
                ErrorCodes.IllegalOperation,
                "Expected insert to fail because database is in read-only mode");

            // Test that delete fails.
            assert.writeErrorWithCode(
                readableCollection.remove({x: 1}),
                ErrorCodes.IllegalOperation,
                "Expected remove to fail because database is in read-only mode");

            // Test that update fails.
            assert.writeErrorWithCode(
                readableCollection.update({_id: 0}, {$inc: {x: 1}}),
                ErrorCodes.IllegalOperation,
                "Expected update to fail because database is in read-only mode");
        }
    };
}());