blob: ef5f8762a42f6a3fb0503642629aadd10e3ec8cc (
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
|
/**
* 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.
*/
(function() {
"use strict";
var collName = 'leaves';
var commands = [];
commands.push({count: collName, query: {type: 'oak'}});
commands.push({aggregate: collName, pipeline: [{$sort: {type: 1}}]});
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);
});
});
})();
|