Skip to content

Commit d909132

Browse files
committed
tech feedback
1 parent b480a37 commit d909132

File tree

5 files changed

+41
-247
lines changed

5 files changed

+41
-247
lines changed

source/crud/query/retrieve.txt

Lines changed: 39 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -101,58 +101,25 @@ Find Multiple Documents Example: Full File
101101

102102
The following example finds all documents in the ``restaurants`` collection
103103
in which the value of ``cuisine`` is ``"Italian"``. The example returns a cursor that
104-
references the matched documents and unpacks the documents into a slice.
105-
Select the :guilabel:`Struct` or :guilabel:`bson.D` tab to see the corresponding code:
104+
references the matched documents and unpacks the documents into a slice:
106105

107-
.. tabs::
108-
109-
.. tab :: Struct
110-
:tabid: structExample
111-
112-
The following code uses structs to find and return all documents in the
113-
``restaurants`` collection in which the value of ``cuisine`` is "Italian":
114-
115-
.. io-code-block::
116-
:copyable: true
117-
118-
.. input:: /includes/usage-examples/code-snippets/find.go
119-
:language: go
120-
:dedent:
121-
122-
.. output::
123-
:language: none
124-
:visible: false
125-
126-
// results truncated
127-
...
128-
{ ... , "Name" : "Epistrophy Cafe", "RestaurantId": "41117553", "Cuisine" : "Italian", ... },
129-
{ ... , "Name" : "Remi", "RestaurantId": "41118090", "Cuisine" : "Italian", ... },
130-
{ ... , "Name" : "Sant Ambroeus", "RestaurantId": "41120682", "Cuisine" : "Italian", ... },
131-
...
132-
133-
.. tab :: bson.D
134-
:tabid: bsonDExample
135-
136-
The following code uses a bson.D type to find and return all documents in
137-
the ``restaurants`` collection in which the value of ``cuisine`` is "Italian":
138-
139-
.. io-code-block::
140-
:copyable: true
106+
.. io-code-block::
107+
:copyable: true
141108

142-
.. input:: /includes/usage-examples/code-snippets/findBsonD.go
143-
:language: go
144-
:dedent:
109+
.. input:: /includes/usage-examples/code-snippets/find.go
110+
:language: go
111+
:dedent:
145112

146-
.. output::
147-
:language: none
148-
:visible: false
113+
.. output::
114+
:language: none
115+
:visible: false
149116

150-
// results truncated
151-
...
152-
{ ... , "Name" : "Epistrophy Cafe", "RestaurantId": "41117553", "Cuisine" : "Italian", ... },
153-
{ ... , "Name" : "Remi", "RestaurantId": "41118090", "Cuisine" : "Italian", ... },
154-
{ ... , "Name" : "Sant Ambroeus", "RestaurantId": "41120682", "Cuisine" : "Italian", ... },
155-
...
117+
// results truncated
118+
...
119+
{ ... , "Name" : "Epistrophy Cafe", "RestaurantId": "41117553", "Cuisine" : "Italian", ... },
120+
{ ... , "Name" : "Remi", "RestaurantId": "41118090", "Cuisine" : "Italian", ... },
121+
{ ... , "Name" : "Sant Ambroeus", "RestaurantId": "41120682", "Cuisine" : "Italian", ... },
122+
...
156123

157124
.. _golang-find-one-example:
158125

@@ -247,67 +214,30 @@ Find One Document Example: Full File
247214

248215
.. include:: /includes/usage-examples/example-intro.rst
249216

250-
The following example finds a document in the ``restaurants`` collection that
251-
matches a query filter. Select the :guilabel:`Struct` or :guilabel:`bson.D`
252-
tab to see the corresponding code:
253-
254-
.. tabs::
255-
256-
.. tab :: Struct
257-
:tabid: structExample
258-
259-
The following code uses structs to find and return the first document in the
260-
``restaurants`` collection in which the value of ``name`` is "Bagels N Buns":
261-
262-
.. io-code-block::
263-
:copyable: true
264-
265-
.. input:: /includes/usage-examples/code-snippets/findOne.go
266-
:language: go
267-
:dedent:
268-
269-
.. output::
270-
:language: none
271-
:visible: false
272-
273-
// results truncated
274-
{
275-
"ID": "5eb3d668b31de5d588f42950",
276-
"Name": "Bagels N Buns",
277-
"RestaurantId": "40363427"
278-
"Address": [...],
279-
"Borough": "Staten Island",
280-
"Cuisine": "Delicatessen",
281-
"Grades": [...]
282-
}
283-
284-
.. tab :: bson.D
285-
:tabid: bsonDExample
286-
287-
The following code uses a bson.D type to find and return the first document
288-
in the ``restaurants`` collection in which the value of ``name`` is "Bagels N Buns":
289-
290-
.. io-code-block::
291-
:copyable: true
292-
293-
.. input:: /includes/usage-examples/code-snippets/findOneBsonD.go
294-
:language: go
295-
:dedent:
296-
297-
.. output::
298-
:language: none
299-
:visible: false
300-
301-
// results truncated
302-
{
303-
"ID": "5eb3d668b31de5d588f42950",
304-
"Name": "Bagels N Buns",
305-
"RestaurantId": "40363427"
306-
"Address": [...],
307-
"Borough": "Staten Island",
308-
"Cuisine": "Delicatessen",
309-
"Grades": [...]
310-
}
217+
The following example finds and returns the first document in the
218+
``restaurants`` collection in which the value of ``name`` is ``"Bagels N Buns"``:
219+
220+
.. io-code-block::
221+
:copyable: true
222+
223+
.. input:: /includes/usage-examples/code-snippets/findOne.go
224+
:language: go
225+
:dedent:
226+
227+
.. output::
228+
:language: none
229+
:visible: false
230+
231+
// results truncated
232+
{
233+
"ID": "5eb3d668b31de5d588f42950",
234+
"Name": "Bagels N Buns",
235+
"RestaurantId": "40363427"
236+
"Address": [...],
237+
"Borough": "Staten Island",
238+
"Cuisine": "Delicatessen",
239+
"Grades": [...]
240+
}
311241

312242
.. _golang-retrieve-options:
313243

source/includes/usage-examples/code-snippets/find.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ type Restaurant struct {
2525
Grades interface{}
2626
}
2727

28-
// Creates a filter struct to use for the query
29-
type RestaurantCuisineFilter struct {
30-
Cuisine string
31-
}
32-
3328
func main() {
3429
if err := godotenv.Load(); err != nil {
3530
log.Println("No .env file found")
@@ -54,7 +49,7 @@ func main() {
5449

5550
// Creates a query filter to match documents in which the "cuisine"
5651
// is "Italian"
57-
filter := RestaurantCuisineFilter{Cuisine: "Italian"}
52+
filter := bson.D{{"cuisine", "Italian"}}
5853

5954
// Retrieves documents that match the query filter
6055
cursor, err := coll.Find(context.TODO(), filter)
@@ -70,7 +65,6 @@ func main() {
7065

7166
// Prints the results of the find operation as structs
7267
for _, result := range results {
73-
cursor.Decode(&result)
7468
output, err := json.MarshalIndent(result, "", " ")
7569
if err != nil {
7670
panic(err)

source/includes/usage-examples/code-snippets/findBsonD.go

Lines changed: 0 additions & 64 deletions
This file was deleted.

source/includes/usage-examples/code-snippets/findOne.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ type Restaurant struct {
2525
Grades []interface{}
2626
}
2727

28-
// Creates a filter struct to use for the query
29-
type RestaurantNameFilter struct {
30-
Name string
31-
}
32-
3328
func main() {
3429
if err := godotenv.Load(); err != nil {
3530
log.Println("No .env file found")
@@ -54,7 +49,7 @@ func main() {
5449

5550
// Creates a query filter to match documents in which the "name" is
5651
// "Bagels N Buns"
57-
filter := RestaurantNameFilter{Name: "Bagels N Buns"}
52+
filter := bson.D{{"name", "Bagels N Buns"}}
5853

5954
// Retrieves the first matching document
6055
var result Restaurant

source/includes/usage-examples/code-snippets/findOneBsonD.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)