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
#[derive(PartialEq, Eq, Clone)]
pub enum CommandType {
Aggregate,
Count,
CreateCollection,
CreateIndexes,
CreateUser,
DeleteMany,
DeleteOne,
Distinct,
DropAllUsers,
DropCollection,
DropDatabase,
DropIndexes,
DropUser,
Find,
FindOneAndDelete,
FindOneAndReplace,
FindOneAndUpdate,
GetUser,
GetUsers,
InsertMany,
InsertOne,
IsMaster,
ListCollections,
ListDatabases,
ListIndexes,
Suppressed,
UpdateMany,
UpdateOne,
}
impl CommandType {
pub fn to_str(&self) -> &str {
match *self {
CommandType::Aggregate => "aggregate",
CommandType::Count => "count",
CommandType::CreateCollection => "create_collection",
CommandType::CreateIndexes => "create_indexes",
CommandType::CreateUser => "create_user",
CommandType::DeleteMany => "delete_many",
CommandType::DeleteOne => "delete_one",
CommandType::Distinct => "distinct",
CommandType::DropAllUsers => "drop_all_users",
CommandType::DropCollection => "drop_collection",
CommandType::DropDatabase => "drop_database",
CommandType::DropIndexes => "drop_indexes",
CommandType::DropUser => "drop_user",
CommandType::Find => "find",
CommandType::FindOneAndDelete => "find_one_and_delete",
CommandType::FindOneAndReplace => "find_one_and_replace",
CommandType::FindOneAndUpdate => "find_one_and_update",
CommandType::GetUser => "get_user",
CommandType::GetUsers => "get_users",
CommandType::InsertMany => "insert_many",
CommandType::InsertOne => "insert_one",
CommandType::IsMaster => "is_master",
CommandType::ListCollections => "list_collections",
CommandType::ListDatabases => "list_databases",
CommandType::ListIndexes => "list_indexes",
CommandType::Suppressed => "suppressed",
CommandType::UpdateMany => "update_many",
CommandType::UpdateOne => "update_one",
}
}
pub fn is_write_command(&self) -> bool {
match *self {
CommandType::Aggregate => false,
CommandType::Count => false,
CommandType::CreateCollection => true,
CommandType::CreateIndexes => true,
CommandType::CreateUser => true,
CommandType::DeleteMany => true,
CommandType::DeleteOne => true,
CommandType::Distinct => false,
CommandType::DropAllUsers => true,
CommandType::DropCollection => true,
CommandType::DropDatabase => true,
CommandType::DropIndexes => true,
CommandType::DropUser => true,
CommandType::Find => false,
CommandType::FindOneAndDelete => true,
CommandType::FindOneAndReplace => true,
CommandType::FindOneAndUpdate => true,
CommandType::GetUser => false,
CommandType::GetUsers => false,
CommandType::InsertMany => true,
CommandType::InsertOne => true,
CommandType::IsMaster => false,
CommandType::ListCollections => false,
CommandType::ListDatabases => false,
CommandType::ListIndexes => false,
CommandType::Suppressed => false,
CommandType::UpdateMany => true,
CommandType::UpdateOne => true,
}
}
}