This repository has been archived by the owner on Jun 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathop.go
64 lines (55 loc) · 1.58 KB
/
op.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
package flashback
import (
"time"
"gopkg.in/mgo.v2/bson"
)
// OpType is the name of mongo op type
type OpType string
// Document represents the json-like infromation of an op
type Document map[string]interface{}
// Contains a list of mongo op types
const (
Insert OpType = "insert"
Update OpType = "update"
Remove OpType = "remove"
Query OpType = "query"
Command OpType = "command"
Count OpType = "command.count"
FindAndModify OpType = "command.findandmodify"
GetMore OpType = "getmore"
)
// AllOpTypes specifies all supported op types
var AllOpTypes = []OpType{
Insert,
Update,
Remove,
Query,
Count,
FindAndModify,
GetMore,
}
// Op represents an op generated by the record utility
// It must (currently) be massaged a little before handing off to the executor
type Op struct {
Ns string `bson:"ns"`
Timestamp time.Time `bson:"ts"`
Type OpType `bson:"op"`
NToSkip int64 `bson:"ntoskip,omitempty"`
NToReturn int64 `bson:"ntoreturn,omitempty"`
QueryDoc bson.D `bson:"query,omitempty"`
CommandDoc bson.D `bson:"command,omitempty"`
InsertDoc bson.D `bson:"o,omitempty"`
UpdateDoc bson.D `bson:"updateobj,omitempty"`
Database string `bson:",omitempty"`
Collection string `bson:",omitempty"`
}
// GetElem is a helper to fetch a specific key from bson.D
// The second return value indicates whether or not the key exists
func GetElem(doc bson.D, key string) (interface{}, bool) {
for _, elem := range doc {
if elem.Name == key {
return elem.Value, true
}
}
return nil, false
}