Skip to content

Commit 9174e2e

Browse files
committed
SELECT - Add missing console output to help attendees see their code worked
1 parent f5075bf commit 9174e2e

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

docs/40-CRUD/2-SELECT.mdx

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,21 @@ Here:
103103
<TabItem value="csharp" label="C#">
104104
<div>
105105
```csharp
106-
var projection = Builders<Book>.Projection.Include(b => b.Title).Exclude(b => b.Id);
107-
booksCollection.Find(b => true).Project<Book>(projection);
106+
var projection = Builders<Book>.Projection.Include(b => b.Title).Exclude(b => b.Id);
107+
108+
var booksWithOnlyTitle = booksCollection.Find(b => true).Project<Book>(projection).Limit(50).ToList();
109+
110+
if(booksWithOnlyTitle != null)
111+
{
112+
foreach(var book in booksWithOnlyTitle)
113+
{
114+
Console.WriteLine(book.ToJson()); // Shows the entire BSON document as JSON to show that some fields are null because they are not returned due to the projection
115+
}
116+
}
117+
else
118+
{
119+
Console.WriteLine("Empty Collection");
120+
}
108121
```
109122
</div>
110123
</TabItem>
@@ -141,19 +154,19 @@ Here:
141154
var projection = Builders<Book>.Projection.Exclude(b => b.Id).Exclude(b => b.Authors);
142155

143156
List<Book> sortedBooks = booksCollection.Find(historyGenre)
144-
.Project<Book>(projection).ToList();
145-
146-
if(sortedBooks != null)
147-
{
148-
foreach(var book in sortedBooks)
149-
{
150-
Console.WriteLine(book.ToJson()); // Shows the entire BSON document as JSON to show that some fields are null because they are not returned due to the projection
151-
}
152-
}
153-
else
154-
{
155-
Console.WriteLine("Empty Collection");
156-
}
157+
.Project<Book>(projection).Limit(50).ToList();
158+
159+
if(sortedBooks != null)
160+
{
161+
foreach(var book in sortedBooks)
162+
{
163+
Console.WriteLine(book.ToJson()); // Shows the entire BSON document as JSON to show that some fields are null because they are not returned due to the projection
164+
}
165+
}
166+
else
167+
{
168+
Console.WriteLine("Empty Collection");
169+
}
157170
```
158171
</div>
159172
</TabItem>

0 commit comments

Comments
 (0)