/
collection.go
82 lines (79 loc) · 2.56 KB
/
collection.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
package mongodb
import (
"context"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
// Collection is an interface for the subset of *mongo.Collection functions that
// we actually use. Using this interface in our datastores, instead of using the
// *mongo.Collection type directly, allows for the possibility of utilizing a
// mock implementation for testing purposes. Adding only the subset of functions
// that we actually use limits the effort involved in creating such mocks.
type Collection interface {
// CountDocuments returns the number of documents in the collection.
CountDocuments(
ctx context.Context,
filter interface{},
opts ...*options.CountOptions,
) (int64, error)
// DeleteMany executes a delete command to delete documents from the
// collection.
DeleteMany(
ctx context.Context,
filter interface{},
opts ...*options.DeleteOptions,
) (*mongo.DeleteResult, error)
// DeleteOne executes a delete command to delete at most one document from the
// collection.
DeleteOne(
ctx context.Context,
filter interface{},
opts ...*options.DeleteOptions,
) (*mongo.DeleteResult, error)
// Find executes a find command and returns a Cursor over the matching
// documents in the collection.
Find(
ctx context.Context,
filter interface{},
opts ...*options.FindOptions,
) (*mongo.Cursor, error)
// FindOne executes a find command and returns a SingleResult for one document
// in the collection.
FindOne(
ctx context.Context,
filter interface{},
opts ...*options.FindOneOptions,
) *mongo.SingleResult
// FindOneAndReplace executes a findAndModify command to replace at most one
// document in the collection and returns the document as it appeared before
// replacement.
FindOneAndReplace(
ctx context.Context,
filter interface{},
replacement interface{},
opts ...*options.FindOneAndReplaceOptions,
) *mongo.SingleResult
// InsertOne executes an insert command to insert a single document into the
// collection.
InsertOne(
ctx context.Context,
document interface{},
opts ...*options.InsertOneOptions,
) (*mongo.InsertOneResult, error)
// UpdateMany executes an update command to update documents in the
// collection.
UpdateMany(
ctx context.Context,
filter interface{},
update interface{},
opts ...*options.UpdateOptions,
) (*mongo.UpdateResult, error)
// UpdateOne executes an update command to update at most one document in the
// collection.
UpdateOne(
ctx context.Context,
filter interface{},
update interface{},
opts ...*options.UpdateOptions,
) (*mongo.UpdateResult, error)
}