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
|
/**
* Tests the behavior of listCollections in the presence of both a time-series collection and an
* invalid view definition.
*
* @tags: [
* assumes_against_mongod_not_mongos,
* does_not_support_transactions,
* requires_getmore,
* ]
*/
(function() {
'use strict';
const testDB = db.getSiblingDB(jsTestName());
assert.commandWorked(testDB.dropDatabase());
const timeFieldName = 'time';
const coll = testDB.getCollection('t');
assert.commandWorked(
testDB.createCollection(coll.getName(), {timeseries: {timeField: timeFieldName}}));
assert.commandWorked(testDB.adminCommand({
applyOps: [
{op: 'i', ns: testDB.getName() + '.system.views', o: {_id: 'invalid', pipeline: 'invalid'}}
]
}));
assert.commandFailedWithCode(testDB.runCommand({listCollections: 1}),
ErrorCodes.InvalidViewDefinition);
assert.commandFailedWithCode(testDB.runCommand({listCollections: 1, filter: {type: 'timeseries'}}),
ErrorCodes.InvalidViewDefinition);
assert.commandFailedWithCode(
testDB.runCommand({listCollections: 1, filter: {name: coll.getName()}}),
ErrorCodes.InvalidViewDefinition);
// TODO (SERVER-25493): Change filter to {type: 'collection'}.
const collections =
assert
.commandWorked(testDB.runCommand(
{listCollections: 1, filter: {$or: [{type: 'collection'}, {type: {$exists: false}}]}}))
.cursor.firstBatch;
jsTestLog('Checking listCollections result: ' + tojson(collections));
assert.eq(collections.length, 2);
assert(collections.find(entry => entry.name === 'system.views'));
assert(collections.find(entry => entry.name === 'system.buckets.' + coll.getName()));
// Users are prohibited from dropping system.views when there are time-series collections present.
// However, this restriction isn't in place on earlier versions and its possible for users to
// upgrade to this version with a dropped system.views collection while having time-series
// collections present. This allows us to continue to test the behaviour of this scenario.
assert.commandWorked(
testDB.adminCommand({configureFailPoint: "allowSystemViewsDrop", mode: "alwaysOn"}));
assert(testDB.system.views.drop());
assert.commandWorked(
testDB.adminCommand({configureFailPoint: "allowSystemViewsDrop", mode: "off"}));
})();
|