Skip to content

Commit efde7e6

Browse files
committed
NR review and tech feedback
1 parent 09f485b commit efde7e6

File tree

3 files changed

+15
-115
lines changed

3 files changed

+15
-115
lines changed

source/crud/query/count.txt

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -242,58 +242,24 @@ Count Documents Example: Full File
242242

243243
.. include:: /includes/usage-examples/example-intro.rst
244244

245-
The following example performs the following on the ``restaurants``
246-
collection:
245+
This example performs the following on the ``restaurants`` collection:
247246

248247
- Approximates the number of documents in the collection
249-
- Counts the number of documents in which the value of the ``cuisine`` is "American"
248+
- Counts the number of documents in which the value of the ``cuisine`` field is ``"American"``
250249

251-
Select the :guilabel:`Struct` or :guilabel:`bson.D` tab to see the corresponding code:
252-
253-
.. tabs::
254-
255-
.. tab :: Struct
256-
:tabid: structExample
257-
258-
The following code uses structs to approximate the number of documents in
259-
the collection and count the number of documents in which the value of the
260-
``cuisine`` is "American":
261-
262-
.. io-code-block::
263-
:copyable: true
264-
265-
.. input:: /includes/usage-examples/code-snippets/count.go
266-
:language: go
267-
:dedent:
268-
269-
.. output::
270-
:language: none
271-
:visible: false
272-
273-
Estimated number of documents in the restaurants collection: 25359
274-
Number of restaurants with American cuisine: 6183
275-
276-
.. tab :: bson.D
277-
:tabid: bsonDExample
278-
279-
The following code uses a bson.D type to approximate the number of documents in
280-
the collection and count the number of documents in which the value of the
281-
``cuisine`` is "American":
282-
283-
.. io-code-block::
284-
:copyable: true
285-
286-
.. input:: /includes/usage-examples/code-snippets/countBsonD.go
287-
:language: go
288-
:dedent:
250+
.. io-code-block::
251+
:copyable: true
289252

290-
.. output::
291-
:language: none
292-
:visible: false
253+
.. input:: /includes/usage-examples/code-snippets/count.go
254+
:language: go
255+
:dedent:
293256

294-
Estimated number of documents in the restaurants collection: 25359
295-
Number of restaurants with American cuisine: 6183
257+
.. output::
258+
:language: none
259+
:visible: false
296260

261+
Estimated number of documents in the restaurants collection: 25359
262+
Number of restaurants with American cuisine: 6183
297263

298264
Additional Information
299265
----------------------

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ type Restaurant struct {
2323
Grades interface{}
2424
}
2525

26-
// Creates a filter struct to use for the query
27-
type RestaurantCuisineFilter struct {
28-
Cuisine string
29-
}
30-
3126
func main() {
3227
if err := godotenv.Load(); err != nil {
3328
log.Println("No .env file found")
@@ -50,18 +45,17 @@ func main() {
5045

5146
coll := client.Database("sample_restaurants").Collection("restaurants")
5247

53-
// Specifies a filter to match documents where the "cuisine"
48+
// Specifies a filter to match documents where the "cuisine" field
5449
// has a value of "American"
55-
filter := RestaurantCuisineFilter{Cuisine: "American"}
50+
filter := bson.D{{"cuisine", "American"}}
5651

5752
// Retrieves and prints the estimated number of documents in the collection
5853
estCount, estCountErr := coll.EstimatedDocumentCount(context.TODO())
5954
if estCountErr != nil {
6055
panic(estCountErr)
6156
}
6257

63-
// Retrieves and prints the number of documents in the collection
64-
// that match the filter
58+
// Retrieves and prints the number of matching documents in the collection
6559
count, err := coll.CountDocuments(context.TODO(), filter)
6660
if err != nil {
6761
panic(err)

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

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

0 commit comments

Comments
 (0)