Skip to content

Commit 5fd0a9b

Browse files
authored
DOCSP-40654-sample-aggregation-operator (mongodb#360)
* DOCSP-40654-sample-aggregation-operator * changed some syntax * update code example
1 parent 6d6bd6f commit 5fd0a9b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

source/fundamentals/linq.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,32 @@ The result of the preceding example contains the following documents:
249249
{ "name" : "Crystal Room", "cuisine" : "Italian" }
250250
{ "name" : "Forlinis Restaurant", "cuisine" : "Italian" }
251251

252+
$sample
253+
~~~~~~~
254+
255+
The ``$sample`` aggregation stage returns a random sample of documents from a
256+
collection. The following example shows how to generate a ``$sample`` stage by using
257+
LINQ:
258+
259+
.. code-block:: csharp
260+
:emphasize-lines: 4
261+
262+
var query = queryableCollection
263+
.Aggregate()
264+
.Sample(4)
265+
.ToList();
266+
267+
The result of the preceding example contains the following documents:
268+
269+
.. code-block:: json
270+
271+
// Results Truncated
272+
273+
{ "name" : "Von Dolhens", "cuisine" : "Ice Cream, Gelato, Yogurt, Ices" }
274+
{ "name" : "New York Mercantile Exchange", "cuisine" : "American" }
275+
{ "name" : "Michaelangelo's Restaurant", "cuisine" : "Italian" }
276+
{ "name" : "Charlie Palmer Steak", "cuisine" : "American" }
277+
252278
$skip
253279
~~~~~
254280

0 commit comments

Comments
 (0)