...
1
2
3
4
5
6
7 package writeconcern_test
8
9 import (
10 "context"
11
12 "go.mongodb.org/mongo-driver/mongo"
13 "go.mongodb.org/mongo-driver/mongo/options"
14 "go.mongodb.org/mongo-driver/mongo/writeconcern"
15 )
16
17
18
19 func Example_majority() {
20 wc := writeconcern.Majority()
21
22 opts := options.Client().
23 ApplyURI("mongodb://localhost:27017").
24 SetWriteConcern(wc)
25
26 _, err := mongo.Connect(context.Background(), opts)
27 if err != nil {
28 panic(err)
29 }
30 }
31
32
33
34 func Example_w2Journaled() {
35 wc := &writeconcern.WriteConcern{
36 W: 2,
37 Journal: boolPtr(true),
38 }
39
40 opts := options.Client().
41 ApplyURI("mongodb://localhost:27017").
42 SetWriteConcern(wc)
43
44 _, err := mongo.Connect(context.Background(), opts)
45 if err != nil {
46 panic(err)
47 }
48 }
49
50
51
52
53
54
55
56
57
58 func boolPtr(b bool) *bool {
59 return &b
60 }
61
View as plain text