File tree Expand file tree Collapse file tree 3 files changed +11
-101
lines changed
includes/usage-examples/code-snippets Expand file tree Collapse file tree 3 files changed +11
-101
lines changed Original file line number Diff line number Diff line change @@ -131,47 +131,18 @@ collection:
131131- Matches a document in which the value of ``name`` is "Rizzo's Fine Pizza"
132132- Replaces the matched document with a new document
133133
134- Select the :guilabel:`Struct` or :guilabel:`bson.D` tab to see the corresponding code:
135-
136- .. tabs::
137-
138- .. tab :: Struct
139- :tabid: structExample
140-
141- The following code uses structs to replace a document, in which the value of
142- ``name`` is "Rizzo's Fine Pizza", with a new document:
143-
144- .. io-code-block::
145- :copyable: true
146-
147- .. input:: /includes/usage-examples/code-snippets/replace.go
148- :language: go
149- :dedent:
150-
151- .. output::
152- :language: none
153- :visible: false
154-
155- Number of documents replaced: 1
156-
157- .. tab :: bson.D
158- :tabid: bsonDExample
159-
160- The following code uses a bson.D type to replace a document, in which the value of
161- ``name`` is "Rizzo's Fine Pizza", with a new document:
162-
163- .. io-code-block::
164- :copyable: true
134+ .. io-code-block::
135+ :copyable: true
165136
166- .. input:: /includes/usage-examples/code-snippets/replaceBsonD .go
167- :language: go
168- :dedent:
137+ .. input:: /includes/usage-examples/code-snippets/replace .go
138+ :language: go
139+ :dedent:
169140
170- .. output::
171- :language: none
172- :visible: false
141+ .. output::
142+ :language: none
143+ :visible: false
173144
174- Number of documents replaced: 1
145+ Number of documents replaced: 1
175146
176147Expected Result
177148~~~~~~~~~~~~~~~
Original file line number Diff line number Diff line change 88 "os"
99
1010 "github.com/joho/godotenv"
11+ "go.mongodb.org/mongo-driver/v2/bson"
1112 "go.mongodb.org/mongo-driver/v2/mongo"
1213 "go.mongodb.org/mongo-driver/v2/mongo/options"
1314)
@@ -21,10 +22,6 @@ type Restaurant struct {
2122 Grades []interface {} `bson:"grades,omitempty"`
2223}
2324
24- type RestaurantNameFilter struct {
25- Name string
26- }
27-
2825func main () {
2926 if err := godotenv .Load (); err != nil {
3027 log .Println ("No .env file found" )
@@ -46,7 +43,7 @@ func main() {
4643 }()
4744
4845 coll := client .Database ("sample_restaurants" ).Collection ("restaurants" )
49- filter := RestaurantNameFilter { Name : "Rizzo's Fine Pizza" }
46+ filter := bson. D {{ "name" , "Rizzo's Fine Pizza" } }
5047
5148 // Creates a new document containing "Name" and "Cuisine" fields
5249 replacement := Restaurant {Name : "Rizzo's Pizza" , Cuisine : "Pizza/American" }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments