Skip to content

Commit 7bf73fd

Browse files
authored
Merge pull request #33 from mongodb-developer/indentation-changes
Make a couple of indentation changes for readability
2 parents 7e9f68d + 4407572 commit 7bf73fd

File tree

6 files changed

+76
-48
lines changed

6 files changed

+76
-48
lines changed

docs/40-CRUD/1-WHERE.mdx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ Now, translate the following into a MongoDB query.
120120

121121
List<Book> filteredBooks = booksCollection.Find(booksWithTotalInventoryOf5).ToList<Book>();
122122

123-
if(filteredBooks != null)
123+
if (filteredBooks != null)
124124
{
125-
foreach(var book in filteredBooks)
125+
foreach (var book in filteredBooks)
126126
{
127127
Console.WriteLine($"Book Title: {book.Title} - Total Inventory: {book.TotalInventory}");
128128
}
@@ -164,9 +164,9 @@ Now, translate the following into a MongoDB query.
164164

165165
List<Book> filteredBooks = booksCollection.Find(booksWithMoreThan300Pages).ToList<Book>();
166166

167-
if(filteredBooks != null)
167+
if (filteredBooks != null)
168168
{
169-
foreach(var book in filteredBooks)
169+
foreach (var book in filteredBooks)
170170
{
171171
Console.WriteLine($"Book Title: {book.Title} - Pages: {book.Pages}");
172172
}
@@ -203,7 +203,16 @@ Now, translate the following into a MongoDB query.
203203
<TabItem value="csharp" label="C#">
204204
<div>
205205
```csharp
206-
var booksWithGenreScienceAndMoreThan300Pages = Builders<Book>.Filter.And(Builders<Book>.Filter.AnyEq(b => b.Genres, "Science"), Builders<Book>.Filter.Gt(b => b.Pages, 300));
206+
var booksWithGenreScienceAndMoreThan300Pages = Builders<Book>
207+
.Filter
208+
.And(
209+
Builders<Book>
210+
.Filter
211+
.AnyEq(b => b.Genres, "Science"),
212+
Builders<Book>
213+
.Filter
214+
.Gt(b => b.Pages, 300)
215+
);
207216

208217
var filteredBooks = booksCollection
209218
.Find(booksWithGenreScienceAndMoreThan300Pages)

docs/40-CRUD/2-SELECT.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ Here:
107107

108108
var booksWithOnlyTitle = booksCollection.Find(b => true).Project<Book>(projection).Limit(50).ToList();
109109

110-
if(booksWithOnlyTitle != null)
110+
if (booksWithOnlyTitle != null)
111111
{
112-
foreach(var book in booksWithOnlyTitle)
112+
foreach (var book in booksWithOnlyTitle)
113113
{
114114
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
115115
}
@@ -156,9 +156,9 @@ Here:
156156
List<Book> sortedBooks = booksCollection.Find(historyGenre)
157157
.Project<Book>(projection).Limit(50).ToList();
158158

159-
if(sortedBooks != null)
159+
if (sortedBooks != null)
160160
{
161-
foreach(var book in sortedBooks)
161+
foreach (var book in sortedBooks)
162162
{
163163
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
164164
}

docs/50-aggregation/2-match-project.mdx

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,22 @@ db.books.aggregate([
121121
<TabItem value="csharp" label="C#">
122122
<div>
123123
```csharp
124-
var pipeline = booksCollection.Aggregate()
125-
.Match(b => b.Available > 2);
126-
127-
var plentifulBooks = pipeline.ToList();
128-
129-
if(plentifulBooks != null)
130-
{
131-
foreach(var book in plentifulBooks)
132-
{
133-
Console.WriteLine($"Title: {book.Title} - Available: {book.Available}");
134-
}
135-
}
136-
else
137-
{
138-
Console.WriteLine("Empty Collection");
139-
}
124+
var pipeline = booksCollection.Aggregate()
125+
.Match(b => b.Available > 2);
126+
127+
var plentifulBooks = pipeline.ToList();
128+
129+
if (plentifulBooks != null)
130+
{
131+
foreach (var book in plentifulBooks)
132+
{
133+
Console.WriteLine($"Title: {book.Title} - Available: {book.Available}");
134+
}
135+
}
136+
else
137+
{
138+
Console.WriteLine("Empty Collection");
139+
}
140140
```
141141
</div>
142142
</TabItem>
@@ -171,23 +171,23 @@ db.books.aggregate([
171171
<TabItem value="csharp" label="C#">
172172
<div>
173173
```csharp
174-
var pipeline = booksCollection.Aggregate()
175-
.Match(b => b.Available > 2)
176-
.Project(b => new { b.Title, b.Year });
174+
var pipeline = booksCollection.Aggregate()
175+
.Match(b => b.Available > 2)
176+
.Project(b => new { b.Title, b.Year });
177177

178-
var plentifulBooks = pipeline.ToList();
178+
var plentifulBooks = pipeline.ToList();
179179

180-
if(plentifulBooks != null)
181-
{
182-
foreach(var book in plentifulBooks)
183-
{
184-
Console.WriteLine($"Title: {book.Title} - Year: {book.Year}");
185-
}
186-
}
187-
else
180+
if (plentifulBooks != null)
181+
{
182+
foreach (var book in plentifulBooks)
188183
{
189-
Console.WriteLine("Empty Collection");
184+
Console.WriteLine($"Title: {book.Title} - Year: {book.Year}");
190185
}
186+
}
187+
else
188+
{
189+
Console.WriteLine("Empty Collection");
190+
}
191191
```
192192
</div>
193193
</TabItem>

docs/50-aggregation/3-sort-limit.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,18 @@ Learn [when to use $addFields over $project](https://www.practical-mongodb-aggre
171171
<TabItem value="addFields" label="Using $addFields">
172172
<div>
173173
```csharp
174-
var pipeline = booksCollection.Aggregate()
175-
.Match(b => b.Year > 2000)
176-
.Match(Builders<Book>.Filter.Exists(b => b.Authors))
177-
.AppendStage<BsonDocument>(
178-
new BsonDocument("$addFields", new BsonDocument("numAuthors", new BsonDocument("$size", "$authors")))
174+
var pipeline = booksCollection.Aggregate()
175+
.Match(b => b.Year > 2000)
176+
.Match(Builders<Book>.Filter.Exists(b => b.Authors))
177+
.AppendStage<BsonDocument>(
178+
new BsonDocument("$addFields",
179+
new BsonDocument("numAuthors", new BsonDocument("$size", "$authors"))
180+
)
179181
)
180-
.Sort(new BsonDocument("numAuthors", -1))
181-
.Limit(1);
182+
.Sort(new BsonDocument("numAuthors", -1))
183+
.Limit(1);
182184

183-
var mostAuthors = pipeline.ToList();
185+
var mostAuthors = pipeline.ToList();
184186
```
185187
</div>
186188
</TabItem>

docs/50-aggregation/4-group.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ GROUP BY year;
159159
[BsonElement("avgRating")]
160160
public double AvgRating { get; set; }
161161
}
162+
162163
var pipeline = reviewsCollection.Aggregate()
163164
.Group(
164165
r => r.BookId,

docs/50-aggregation/7-merge.mdx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,24 @@ ON DUPLICATE KEY UPDATE totalBooks = VALUES(totalBooks);
165165
```csharp
166166
var pipeline = authorsCollection.Aggregate()
167167
.AppendStage<BsonDocument>(new BsonDocument{"$unwind", "$books"})
168-
.AppendStage<BsonDocument>(new BsonDocument{"$group", new BsonDocument{{"_id","$name"},{"totalBooks", new BsonDocument{"$sum", 1}}}})
169-
.AppendStage<BsonDocument>(new BsonDocument{"$merge", new BsonDocument{{"into","author_stats"},{"on","_id"},{"whenMatched","merge"},{"whenNotMatched","insert"}}});
168+
.AppendStage<BsonDocument>(new BsonDocument{
169+
"$group",
170+
new BsonDocument{
171+
{"_id","$name"},
172+
{"totalBooks", new BsonDocument{"$sum", 1}}
173+
}
174+
}
175+
)
176+
.AppendStage<BsonDocument>(new BsonDocument{
177+
"$merge",
178+
new BsonDocument{
179+
{"into","author_stats"},
180+
{"on","_id"},
181+
{"whenMatched","merge"},
182+
{"whenNotMatched","insert"}
183+
}
184+
}
185+
);
170186

171187
var result = pipeline.ToList();
172188
```

0 commit comments

Comments
 (0)