read_concern.js
1.3 KB
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
'use strict';
/**
* The **ReadConcern** class is a class that represents a MongoDB ReadConcern.
* @class
* @property {string} level The read concern level
* @see https://docs.mongodb.com/manual/reference/read-concern/index.html
*/
class ReadConcern {
/**
* Constructs a ReadConcern from the read concern properties.
* @param {string} [level] The read concern level ({'local'|'available'|'majority'|'linearizable'|'snapshot'})
*/
constructor(level) {
if (level != null) {
this.level = level;
}
}
/**
* Construct a ReadConcern given an options object.
*
* @param {object} options The options object from which to extract the write concern.
* @return {ReadConcern}
*/
static fromOptions(options) {
if (options == null) {
return;
}
if (options.readConcern) {
if (options.readConcern instanceof ReadConcern) {
return options.readConcern;
}
return new ReadConcern(options.readConcern.level);
}
if (options.level) {
return new ReadConcern(options.level);
}
}
static get MAJORITY() {
return 'majority';
}
static get AVAILABLE() {
return 'available';
}
static get LINEARIZABLE() {
return 'linearizable';
}
static get SNAPSHOT() {
return 'snapshot';
}
}
module.exports = ReadConcern;