summaryrefslogtreecommitdiff
path: root/jstests/core/collation_convert_to_capped.js
blob: db79288f51bfa1f6de40ec8dab43a4017edd2520 (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
// Test that the collection created with the "convertToCapped" command inherits the default
// collation of the corresponding collection.
(function() {
    "use strict";

    let testDb = db.getSiblingDB("collation_convert_to_capped");
    let coll = testDb.coll;
    testDb.dropDatabase();

    // Create a collection with a non-simple default collation.
    assert.commandWorked(
        testDb.runCommand({create: coll.getName(), collation: {locale: "en", strength: 2}}));
    const originalCollectionInfos = testDb.getCollectionInfos({name: coll.getName()});
    assert.eq(originalCollectionInfos.length, 1, tojson(originalCollectionInfos));

    assert.writeOK(coll.insert({_id: "FOO"}));
    assert.writeOK(coll.insert({_id: "bar"}));
    assert.eq([{_id: "FOO"}],
              coll.find({_id: "foo"}).toArray(),
              "query should have performed a case-insensitive match");

    assert.commandWorked(testDb.runCommand({convertToCapped: coll.getName(), size: 4096}));
    const cappedCollectionInfos = testDb.getCollectionInfos({name: coll.getName()});
    assert.eq(cappedCollectionInfos.length, 1, tojson(cappedCollectionInfos));
    assert.eq(originalCollectionInfos[0].options.collation,
              cappedCollectionInfos[0].options.collation);
    assert.eq([{_id: "FOO"}], coll.find({_id: "foo"}).toArray());
})();