summaryrefslogtreecommitdiff
path: root/jstests/core/views/duplicate_ns.js
blob: 2ef02cd6bc1565cec95a4cdf098b408cae9ebc3f (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
// @tags: [
//   assumes_superuser_permissions,
//   requires_non_retryable_writes,
// ]

// Test the creation of view with a duplicate name to a collection.

(function() {
    "use strict";

    const dbName = "views_duplicate_ns";
    const viewsDb = db.getSiblingDB(dbName);
    const collName = "myns";
    const viewId = dbName + "." + collName;

    assert.commandWorked(viewsDb.dropDatabase());
    assert.writeOK(viewsDb.system.views.remove({_id: viewId}));
    assert.commandWorked(viewsDb.runCommand({create: collName}));
    assert.writeOK(viewsDb.system.views.insert({
        _id: viewId,
        viewOn: "coll",
        pipeline: [],
    }));
    assert.eq(2,
              viewsDb.getCollectionInfos()
                  .filter(coll => {
                      return coll.name === collName;
                  })
                  .length);
}());