From f447f2a77a78e869bcd4ac8e5738b42218c1a982 Mon Sep 17 00:00:00 2001 From: Grace Miller Date: Fri, 6 Dec 2024 14:21:26 -0500 Subject: [PATCH 1/3] DOCSP-40654-sample-aggregation-operator --- source/fundamentals/linq.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/fundamentals/linq.txt b/source/fundamentals/linq.txt index 491c98e7..4d867797 100644 --- a/source/fundamentals/linq.txt +++ b/source/fundamentals/linq.txt @@ -249,6 +249,34 @@ The result of the preceding example contains the following documents: { "name" : "Crystal Room", "cuisine" : "Italian" } { "name" : "Forlinis Restaurant", "cuisine" : "Italian" } +$sample +~~~~~~~ + +The ``$sample`` aggregation stage returns a random sample of documents from a +collection. The following example shows how to generate a ``$sample`` stage using +LINQ: + +.. code-block:: csharp + :emphasize-lines: 4 + + var query = await client.GetDatabase("sample_mflix") + .GetCollection("movies") + .Aggregate() + .Sample(4) + .ToListAsync(); + +The result of the preceding example contains the following documents: + +.. code-block:: json + + // Results Truncated + + { "title" : "State of Play", "languages" : ["English"]} + { "title" : "Bhopal: A Prayer for Rain", "languages" : ["English", "Hindi"] } + { "title" : "Dead Presidents", "languages" : ["English"]} + { "title" : "The Rains Came", "languages" : ["English"] } + + $skip ~~~~~ From b4d44cc2a372b5a3b1becd57d50185f702c3f120 Mon Sep 17 00:00:00 2001 From: Grace Miller Date: Mon, 9 Dec 2024 13:58:48 -0500 Subject: [PATCH 2/3] changed some syntax --- source/fundamentals/linq.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/fundamentals/linq.txt b/source/fundamentals/linq.txt index 4d867797..94b297d7 100644 --- a/source/fundamentals/linq.txt +++ b/source/fundamentals/linq.txt @@ -253,17 +253,16 @@ $sample ~~~~~~~ The ``$sample`` aggregation stage returns a random sample of documents from a -collection. The following example shows how to generate a ``$sample`` stage using +collection. The following example shows how to generate a ``$sample`` stage by using LINQ: .. code-block:: csharp :emphasize-lines: 4 - var query = await client.GetDatabase("sample_mflix") - .GetCollection("movies") + var query = queryableCollection .Aggregate() .Sample(4) - .ToListAsync(); + .ToList(); The result of the preceding example contains the following documents: From 6433b05b9465abbdd48a76f11d6da4660aa23a65 Mon Sep 17 00:00:00 2001 From: Grace Miller Date: Wed, 11 Dec 2024 16:39:26 -0500 Subject: [PATCH 3/3] update code example --- source/fundamentals/linq.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/fundamentals/linq.txt b/source/fundamentals/linq.txt index 94b297d7..283714c2 100644 --- a/source/fundamentals/linq.txt +++ b/source/fundamentals/linq.txt @@ -270,11 +270,10 @@ The result of the preceding example contains the following documents: // Results Truncated - { "title" : "State of Play", "languages" : ["English"]} - { "title" : "Bhopal: A Prayer for Rain", "languages" : ["English", "Hindi"] } - { "title" : "Dead Presidents", "languages" : ["English"]} - { "title" : "The Rains Came", "languages" : ["English"] } - + { "name" : "Von Dolhens", "cuisine" : "Ice Cream, Gelato, Yogurt, Ices" } + { "name" : "New York Mercantile Exchange", "cuisine" : "American" } + { "name" : "Michaelangelo's Restaurant", "cuisine" : "Italian" } + { "name" : "Charlie Palmer Steak", "cuisine" : "American" } $skip ~~~~~