| 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | // Package readconcern defines read concerns for MongoDB operations. |
| 8 | // |
| 9 | // For more information about MongoDB read concerns, see |
| 10 | // https://www.mongodb.com/docs/manual/reference/read-concern/ |
| 11 | package readconcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ // import "go.mongodb.org/mongo-driver/mongo/readconcern" |
| 12 | |
| 13 | import ( |
| 14 | "errorsscip-go gomod github.com/golang/go/src go1.18 errors/" |
| 15 | |
| 16 | "go.mongodb.org/mongo-driver/bson/bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/" |
| 17 | "go.mongodb.org/mongo-driver/x/bsonx/bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/" |
| 18 | ) |
| 19 | |
| 20 | // A ReadConcern defines a MongoDB read concern, which allows you to control the consistency and |
| 21 | // isolation properties of the data read from replica sets and replica set shards. |
| 22 | // |
| 23 | // For more information about MongoDB read concerns, see |
| 24 | // https://www.mongodb.com/docs/manual/reference/read-concern/ |
| 25 | type ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern# struct { |
| 26 | Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#Level. string |
| 27 | } |
| 28 | |
| 29 | // Option is an option to provide when creating a ReadConcern. |
| 30 | // |
| 31 | // Deprecated: Use the ReadConcern literal declaration instead. For example: |
| 32 | // |
| 33 | // &readconcern.ReadConcern{Level: "local"} |
| 34 | type Optionscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Option# func(concern *ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#) |
| 35 | |
| 36 | // Level creates an option that sets the level of a ReadConcern. |
| 37 | // |
| 38 | // Deprecated: Use the ReadConcern literal declaration instead. For example: |
| 39 | // |
| 40 | // &readconcern.ReadConcern{Level: "local"} |
| 41 | func Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Level().(level string) Optionscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Option# { |
| 42 | return func(concern *ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#) { |
| 43 | concern.Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#Level. = level |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // Local returns a ReadConcern that requests data from the instance with no guarantee that the data |
| 48 | // has been written to a majority of the replica set members (i.e. may be rolled back). |
| 49 | // |
| 50 | // For more information about read concern "local", see |
| 51 | // https://www.mongodb.com/docs/manual/reference/read-concern-local/ |
| 52 | func Localscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Local().() *ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern# { |
| 53 | return Newscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/New().(Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Level().("local")) |
| 54 | } |
| 55 | |
| 56 | // Majority returns a ReadConcern that requests data that has been acknowledged by a majority of the |
| 57 | // replica set members (i.e. the documents read are durable and guaranteed not to roll back). |
| 58 | // |
| 59 | // For more information about read concern "majority", see |
| 60 | // https://www.mongodb.com/docs/manual/reference/read-concern-majority/ |
| 61 | func Majorityscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Majority().() *ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern# { |
| 62 | return Newscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/New().(Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Level().("majority")) |
| 63 | } |
| 64 | |
| 65 | // Linearizable returns a ReadConcern that requests data that reflects all successful |
| 66 | // majority-acknowledged writes that completed prior to the start of the read operation. |
| 67 | // |
| 68 | // For more information about read concern "linearizable", see |
| 69 | // https://www.mongodb.com/docs/manual/reference/read-concern-linearizable/ |
| 70 | func Linearizablescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Linearizable().() *ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern# { |
| 71 | return Newscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/New().(Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Level().("linearizable")) |
| 72 | } |
| 73 | |
| 74 | // Available returns a ReadConcern that requests data from an instance with no guarantee that the |
| 75 | // data has been written to a majority of the replica set members (i.e. may be rolled back). |
| 76 | // |
| 77 | // For more information about read concern "available", see |
| 78 | // https://www.mongodb.com/docs/manual/reference/read-concern-available/ |
| 79 | func Availablescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Available().() *ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern# { |
| 80 | return Newscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/New().(Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Level().("available")) |
| 81 | } |
| 82 | |
| 83 | // Snapshot returns a ReadConcern that requests majority-committed data as it appears across shards |
| 84 | // from a specific single point in time in the recent past. |
| 85 | // |
| 86 | // For more information about read concern "snapshot", see |
| 87 | // https://www.mongodb.com/docs/manual/reference/read-concern-snapshot/ |
| 88 | func Snapshotscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Snapshot().() *ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern# { |
| 89 | return Newscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/New().(Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Level().("snapshot")) |
| 90 | } |
| 91 | |
| 92 | // New constructs a new read concern from the given string. |
| 93 | // |
| 94 | // Deprecated: Use the ReadConcern literal declaration instead. For example: |
| 95 | // |
| 96 | // &readconcern.ReadConcern{Level: "local"} |
| 97 | func Newscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/New().(options ...Optionscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/Option#) *ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern# { |
| 98 | concern := &ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#{} |
| 99 | |
| 100 | for _, option := range options { |
| 101 | option(concern) |
| 102 | } |
| 103 | |
| 104 | return concern |
| 105 | } |
| 106 | |
| 107 | // MarshalBSONValue implements the bson.ValueMarshaler interface. |
| 108 | // |
| 109 | // Deprecated: Marshaling a ReadConcern to BSON will not be supported in Go Driver 2.0. |
| 110 | func (rc *ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#) MarshalBSONValuescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#MarshalBSONValue().() (bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/.Typescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/Type#, []byte, error) { |
| 111 | if rc == nil { |
| 112 | return 0, nil, errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("cannot marshal nil ReadConcern") |
| 113 | } |
| 114 | |
| 115 | var elems []byte |
| 116 | |
| 117 | if len(rc.Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#Level.) > 0 { |
| 118 | elems = bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.AppendStringElementscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/AppendStringElement().(elems, "level", rc.Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#Level.) |
| 119 | } |
| 120 | |
| 121 | return bsontypescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/.EmbeddedDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/bson/bsontype`/EmbeddedDocument., bsoncorescip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/.BuildDocumentscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/x/bsonx/bsoncore`/BuildDocument().(nil, elems), nil |
| 122 | } |
| 123 | |
| 124 | // GetLevel returns the read concern level. |
| 125 | // |
| 126 | // Deprecated: Use the ReadConcern.Level field instead. |
| 127 | func (rc *ReadConcernscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#) GetLevelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#GetLevel().() string { |
| 128 | return rc.Levelscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/mongo/readconcern`/ReadConcern#Level. |
| 129 | } |