@@ -248,6 +248,44 @@ The result of the preceding example contains the following documents:
248248 { "name" : "Crystal Room", "cuisine" : "Italian" }
249249 { "name" : "Forlinis Restaurant", "cuisine" : "Italian" }
250250
251+ .. _csharp-linq-takewhile:
252+
253+ Limit on a Condition
254+ ````````````````````
255+
256+ You can use the ``TakeWhile()`` LINQ method in a ``Select()`` projection
257+ to return array field elements while a specified condition is true, then
258+ skip the remaining elements.
259+
260+ This example uses the following ``Student`` class to model documents
261+ that contain an array field ``Grades``:
262+
263+ .. code-block:: csharp
264+
265+ public class Student
266+ {
267+ public ObjectId Id { get; set; }
268+ public string Name { get; set; }
269+ public int[] Grades { get; set; }
270+ }
271+
272+ The following code shows how to use the ``TakeWhile()`` method to return
273+ any ``Grades`` array elements that are greater than ``90`` and skip the
274+ rest of the array:
275+
276+ .. code-block:: csharp
277+
278+ var query = queryableCollection
279+ .Select(s => s.Grades.TakeWhile(g => g > 90).ToArray());
280+
281+ The results might resemble the following arrays:
282+
283+ .. code-block:: json
284+ :copyable: false
285+
286+ [92, 97]
287+ [100, 95, 91]
288+
251289$sample
252290~~~~~~~
253291
@@ -301,6 +339,44 @@ returns the rest. The result contains the following documents:
301339 { "name" : "Forlinis Restaurant", "cuisine" : "Italian" }
302340 ...
303341
342+ .. _csharp-linq-skipwhile:
343+
344+ Skip on a Condition
345+ ```````````````````
346+
347+ You can use the ``SkipWhile()`` LINQ method in a ``Select()`` projection
348+ to skip array field elements while a specified condition is true, then
349+ return the remaining elements.
350+
351+ This example uses the following ``Student`` class to model documents
352+ that contain an array field ``Grades``:
353+
354+ .. code-block:: csharp
355+
356+ public class Student
357+ {
358+ public ObjectId Id { get; set; }
359+ public string Name { get; set; }
360+ public int[] Grades { get; set; }
361+ }
362+
363+ The following code shows how to use the ``SkipWhile()`` method to skip
364+ any ``Grades`` array elements that are less than ``75`` and return the
365+ rest of the array:
366+
367+ .. code-block:: csharp
368+
369+ var query = queryableCollection
370+ .Select(s => s.Grades.SkipWhile(g => g < 75).ToArray());
371+
372+ The results might resemble the following arrays:
373+
374+ .. code-block:: json
375+ :copyable: false
376+
377+ [80, 90, 70, 83]
378+ [79, 100, 85, 73]
379+
304380$unwind
305381~~~~~~~
306382
@@ -346,7 +422,7 @@ following documents:
346422 { "date" : ISODate("2012-05-17T00:00:00Z"), "grade" : "A", "score" : 11 }
347423
348424Nested Statements
349- +++++++++++++++++
425+ `````````````````
350426
351427You can chain or nest ``Select`` and ``SelectMany`` statements to unwind nested
352428arrays. Consider a collection that contains documents with a **new** schema. These
@@ -558,7 +634,7 @@ or the ``GroupJoin()`` method. The following sections show how to perform a
558634``$lookup`` by using each method.
559635
560636Lookup()
561- ++++++++
637+ ````````
562638
563639The following code specifies a ``$lookup`` stage by using the ``Lookup()``
564640method. This example joins documents from the ``reviews`` collection to
@@ -768,7 +844,7 @@ collection:
768844 throw an error.
769845
770846$bitAnd
771- +++++++
847+ ```````
772848
773849The ``$bitAnd`` aggregation operator performs a bitwise AND operation on the given
774850arguments. You can use the ``$bitAnd`` operator by connecting two or more
@@ -985,12 +1061,20 @@ The following are some methods supported by the {+driver-long+} implementation o
9851061 * - ``Skip``
9861062 - Skips over a specified number of documents and returns the rest of the results
9871063
1064+ * - ``SkipWhile`` (only in ``Select`` projections)
1065+ - Skips over array elements while a condition is true and returns
1066+ the remaining elements
1067+
9881068 * - ``Sum``
9891069 - Returns the sum of the values in a specified field
9901070
9911071 * - ``Take``
9921072 - Specifies the number of results to return
9931073
1074+ * - ``TakeWhile`` (only in ``Select`` projections)
1075+ - Returns array elements while a condition is true and skips
1076+ the remaining elements
1077+
9941078 * - ``Where``
9951079 - Returns all documents that match your specified criteria
9961080
@@ -1079,4 +1163,5 @@ API Documentation
10791163For a complete list of supported LINQ methods, see the following API documentation:
10801164
10811165- `LINQ <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Linq.html>`__
1082- - `MongoQueryable <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Linq.MongoQueryable.html>`__
1166+ - `MongoQueryable
1167+ <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Linq.MongoQueryable.html>`__
0 commit comments