-
Notifications
You must be signed in to change notification settings - Fork 201
/
storage_protocol.go
157 lines (121 loc) · 4.69 KB
/
storage_protocol.go
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package plugins
import (
"context"
"go.mongodb.org/mongo-driver/bson"
)
// StorageProtocol is the interface that storage plugins must implement.
// This defines the protocol used to communicate with storage plugins.
type StorageProtocol interface {
// EnsureIndex makes sure that the specified index exists as specified.
// If it does exist with a different definition, the index is recreated.
EnsureIndex(ctx context.Context, opts EnsureIndexOptions) error
// Aggregate executes a pipeline and returns the results.
Aggregate(ctx context.Context, opts AggregateOptions) ([]bson.Raw, error)
// Count the number of results that match an optional query.
// When the query is omitted, the entire collection is counted.
Count(ctx context.Context, opts CountOptions) (int64, error)
// Find queries a collection, optionally projecting a subset of fields, and
// then returns the results as a list of bson documents.
Find(ctx context.Context, opts FindOptions) ([]bson.Raw, error)
// Insert a set of documents into a collection.
Insert(ctx context.Context, opts InsertOptions) error
// Patch applies a transformation to matching documents.
Patch(ctx context.Context, opts PatchOptions) error
// Remove matching documents from a collection.
Remove(ctx context.Context, opts RemoveOptions) error
// Update matching documents with the specified replacement document.
Update(ctx context.Context, opts UpdateOptions) error
}
// EnsureIndexOptions is the set of options available to the
// StorageProtocol.EnsureIndex operation.
type EnsureIndexOptions struct {
// Indices to create if not found.
Indices []Index
}
// Index on a collection.
type Index struct {
// Collection name to which the index applies.
Collection string
// Keys describes the fields and their sort order.
// Example: {"namespace": 1, "name": 1}
Keys bson.D
// Unique specifies if the index should enforce that the indexed fields for each document are unique.
Unique bool
}
// AggregateOptions is the set of options available to the
// StorageProtocol.Aggregate operation.
type AggregateOptions struct {
// Collection to query.
Collection string
// Pipeline document to aggregate, filter, and shape the results.
// See https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/
Pipeline []bson.D
}
// CountOptions is the set of options available to the StorageProtocol.Count
// operation.
type CountOptions struct {
// Collection to query.
Collection string
// Query is a query filter document
// See https://docs.mongodb.com/manual/core/document/#std-label-document-query-filter
Filter bson.M
}
// FindOptions is the set of options available to the StorageProtocol.Find
// operation.
type FindOptions struct {
// Collection to query.
Collection string
// Sort is a list of field names by which the results should be sorted.
Sort bson.D
// Skip is the number of results to skip past and exclude from the results.
Skip int64
// Limit is the number of results to return.
Limit int64
// Select is a projection document
// See https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/
Select bson.D
// Filter specifies how to filter the results.
// See https://docs.mongodb.com/manual/core/document/#std-label-document-query-filter
Filter bson.M
}
// InsertOptions is the set of options for the StorageProtocol.Insert operation.
type InsertOptions struct {
// Collection to query.
Collection string
// Documents is a set of documents to insert.
Documents []bson.M
}
// PatchOptions is the set of options for the StorageProtocol.Patch operation.
type PatchOptions struct {
// Collection to query.
Collection string
// Query is a query filter document
// See https://docs.mongodb.com/manual/core/document/#std-label-document-query-filter
QueryDocument bson.M
// Transformation is set of instructions to modify matching
// documents.
Transformation bson.D
}
// RemoveOptions is the set of options for the StorageProtocol.Remove operation.
type RemoveOptions struct {
// Collection to query.
Collection string
// Filter is a query filter document
// See https://docs.mongodb.com/manual/core/document/#std-label-document-query-filter
Filter bson.M
// All matching documents should be removed. Defaults to false, which only
// removes the first matching document.
All bool
}
// UpdateOptions is the set of options for the StorageProtocol.Update operation.
type UpdateOptions struct {
// Collection to query.
Collection string
// Filter is a query filter document
// See https://docs.mongodb.com/manual/core/document/#std-label-document-query-filter
Filter bson.M
// Upsert indicates that the document should be inserted if not found
Upsert bool
// Document is the replacement document.
Document bson.M
}