summaryrefslogtreecommitdiff
path: root/jstests/core/batch_write_collation_estsize.js
blob: 944b20946968f64b9bf1dc33b050ec18d43e1f84 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Tests that the update and delete batch write operations account for the size of the collation
// specification in the write operation document.

(function() {
    "use strict";

    // Setup the test collection.
    db.batch_write_collation_estsize.drop();
    assert.writeOK(db.batch_write_collation_estsize.insert({str: "FOO"}));

    if (db.getMongo().writeMode() !== "commands") {
        // Cannot use the bulk API to set a collation when using legacy write ops.
        let bulk;

        // Test updateOne unordered bulk write operation with collation specification.
        bulk = db.batch_write_collation_estsize.initializeUnorderedBulkOp();
        assert.throws(() => {
            bulk.find({str: "FOO"}).collation({locale: "en_US", strength: 2}).updateOne({
                str: "BAR"
            });
        });

        // Test update unordered bulk write operation with collation specification.
        bulk = db.batch_write_collation_estsize.initializeUnorderedBulkOp();
        assert.throws(() => {
            bulk.find({str: "FOO"}).collation({locale: "en_US", strength: 2}).update({str: "BAR"});
        });

        // Test replaceOne unordered bulk write operation with collation specification.
        bulk = db.batch_write_collation_estsize.initializeUnorderedBulkOp();
        assert.throws(() => {
            bulk.find({str: "FOO"}).collation({locale: "en_US", strength: 2}).replaceOne({
                str: "BAR"
            });
        });

        // Test removeOne unordered bulk write operation with collation specification.
        bulk = db.batch_write_collation_estsize.initializeUnorderedBulkOp();
        assert.throws(() => {
            bulk.find({str: "FOO"}).collation({locale: "en_US", strength: 2}).removeOne();
        });

        // Test remove unordered bulk write operation with collation specification.
        bulk = db.batch_write_collation_estsize.initializeUnorderedBulkOp();
        assert.throws(() => {
            bulk.find({str: "FOO"}).collation({locale: "en_US", strength: 2}).remove();
        });

        // Test updateOne ordered bulk write operation with collation specification.
        bulk = db.batch_write_collation_estsize.initializeOrderedBulkOp();
        assert.throws(() => {
            bulk.find({str: "FOO"}).collation({locale: "en_US", strength: 2}).updateOne({
                str: "BAR"
            });
        });

        // Test update ordered bulk write operation with collation specification.
        bulk = db.batch_write_collation_estsize.initializeOrderedBulkOp();
        assert.throws(() => {
            bulk.find({str: "FOO"}).collation({locale: "en_US", strength: 2}).update({str: "BAR"});
        });

        // Test replaceOne ordered bulk write operation with collation specification.
        bulk = db.batch_write_collation_estsize.initializeOrderedBulkOp();
        assert.throws(() => {
            bulk.find({str: "FOO"}).collation({locale: "en_US", strength: 2}).replaceOne({
                str: "BAR"
            });
        });

        // Test removeOne ordered bulk write operation with collation specification.
        bulk = db.batch_write_collation_estsize.initializeOrderedBulkOp();
        assert.throws(() => {
            bulk.find({str: "FOO"}).collation({locale: "en_US", strength: 2}).removeOne();
        });

        // Test remove ordered bulk write operation with collation specification.
        bulk = db.batch_write_collation_estsize.initializeOrderedBulkOp();
        assert.throws(() => {
            bulk.find({str: "FOO"}).collation({locale: "en_US", strength: 2}).remove();
        });
    } else {
        // Setup the bulk write response variable.
        let res;

        // Test updateOne bulk write operation with collation specification.
        res = db.batch_write_collation_estsize.bulkWrite([{
            updateOne: {
                filter: {str: "FOO"},
                update: {$set: {str: "BAR"}},
                collation: {
                    locale: "en_US",
                    caseLevel: false,
                    caseFirst: "off",
                    strength: 3,
                    numericOrdering: false,
                    alternate: "non-ignorable",
                    maxVariable: "punct",
                    normalization: false,
                    backwards: false
                }
            }
        }]);
        assert.eq(1, res.matchedCount);

        // Test updateMany bulk write operation with collation specification.
        res = db.batch_write_collation_estsize.bulkWrite([{
            updateMany: {
                filter: {str: "BAR"},
                update: {$set: {str: "FOO"}},
                collation: {
                    locale: "en_US",
                    caseLevel: false,
                    caseFirst: "off",
                    strength: 3,
                    numericOrdering: false,
                    alternate: "non-ignorable",
                    maxVariable: "punct",
                    normalization: false,
                    backwards: false
                }
            }
        }]);
        assert.eq(1, res.matchedCount);

        // Test replaceOne bulk write operation with collation specification.
        res = db.batch_write_collation_estsize.bulkWrite([{
            replaceOne: {
                filter: {str: "FOO"},
                replacement: {str: "BAR"},
                collation: {
                    locale: "en_US",
                    caseLevel: false,
                    caseFirst: "off",
                    strength: 3,
                    numericOrdering: false,
                    alternate: "non-ignorable",
                    maxVariable: "punct",
                    normalization: false,
                    backwards: false
                }
            }
        }]);
        assert.eq(1, res.matchedCount);

        // Test deleteMany bulk write operation with collation specification.
        res = db.batch_write_collation_estsize.bulkWrite([{
            deleteOne: {
                filter: {str: "BAR"},
                collation: {
                    locale: "en_US",
                    caseLevel: false,
                    caseFirst: "off",
                    strength: 3,
                    numericOrdering: false,
                    alternate: "non-ignorable",
                    maxVariable: "punct",
                    normalization: false,
                    backwards: false
                }
            }
        }]);
        assert.eq(1, res.deletedCount);

        // Reinsert a document to test deleteMany bulk write operation.
        assert.writeOK(db.batch_write_collation_estsize.insert({str: "FOO"}));

        // Test deleteMany bulk write operation with collation specification.
        res = db.batch_write_collation_estsize.bulkWrite([{
            deleteMany: {
                filter: {str: "FOO"},
                collation: {
                    locale: "en_US",
                    caseLevel: false,
                    caseFirst: "off",
                    strength: 3,
                    numericOrdering: false,
                    alternate: "non-ignorable",
                    maxVariable: "punct",
                    normalization: false,
                    backwards: false
                }
            }
        }]);
        assert.eq(1, res.deletedCount);
    }
})();