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
|
/**
* Tests the result of running listCollections when there are time-series collections present.
*
* @tags: [
* does_not_support_transactions,
* requires_getmore,
* ]
*/
(function() {
'use strict';
const timeFieldName = 'time';
const metaFieldName = 'meta';
const collNamePrefix = 'timeseries_list_collections_';
let collCount = 0;
const getBucketMaxSpanSeconds = function(granularity) {
switch (granularity) {
case 'seconds':
return 60 * 60;
case 'minutes':
return 60 * 60 * 24;
case 'hours':
return 60 * 60 * 24 * 30;
default:
assert(false, 'Invalid granularity: ' + granularity);
}
};
const testOptions = function(options) {
const coll = db.getCollection(collNamePrefix + collCount++);
coll.drop();
jsTestLog('Creating time-series collection with options: ' + tojson(options));
assert.commandWorked(db.createCollection(coll.getName(), options));
if (!options.timeseries.hasOwnProperty('granularity')) {
Object.assign(options.timeseries, {granularity: 'seconds'});
}
if (!options.timeseries.hasOwnProperty('bucketMaxSpanSeconds')) {
Object.assign(
options.timeseries,
{bucketMaxSpanSeconds: getBucketMaxSpanSeconds(options.timeseries.granularity)});
}
if (options.hasOwnProperty('collation')) {
Object.assign(options.collation, {
caseLevel: false,
caseFirst: 'off',
strength: 3,
numericOrdering: false,
alternate: 'non-ignorable',
maxVariable: 'punct',
normalization: false,
backwards: false,
version: '57.1',
});
}
const collections = assert.commandWorked(db.runCommand({listCollections: 1})).cursor.firstBatch;
jsTestLog('Checking listCollections result: ' + tojson(collections));
// Expected number of collections >= system.views + 2 * timeseries collections
// 'test' database may contain collections from other tests running in parallel.
assert.gte(collections.length, (collCount * 2 + 1));
assert(collections.find(entry => entry.name === 'system.views'));
assert(collections.find(entry => entry.name === 'system.buckets.' + coll.getName()));
assert.docEq(
collections.find(entry => entry.name === coll.getName()),
{name: coll.getName(), type: 'timeseries', options: options, info: {readOnly: false}});
};
testOptions({timeseries: {timeField: timeFieldName}});
testOptions({timeseries: {timeField: timeFieldName, metaField: metaFieldName}});
testOptions({
timeseries: {
timeField: timeFieldName,
granularity: 'minutes',
}
});
testOptions({
timeseries: {
timeField: timeFieldName,
granularity: 'minutes',
bucketMaxSpanSeconds: 60 * 60 * 24,
}
});
testOptions({
timeseries: {
timeField: timeFieldName,
},
storageEngine: {wiredTiger: {}},
});
testOptions({
timeseries: {
timeField: timeFieldName,
},
indexOptionDefaults: {storageEngine: {wiredTiger: {}}},
});
testOptions({
timeseries: {
timeField: timeFieldName,
},
collation: {locale: 'ja'},
});
testOptions({timeseries: {timeField: timeFieldName}, expireAfterSeconds: NumberLong(100)});
testOptions({
timeseries: {
timeField: timeFieldName,
metaField: metaFieldName,
granularity: 'minutes',
bucketMaxSpanSeconds: 60 * 60 * 24,
},
storageEngine: {wiredTiger: {}},
indexOptionDefaults: {storageEngine: {wiredTiger: {}}},
collation: {locale: 'ja'},
expireAfterSeconds: NumberLong(100),
});
})();
|