Skip to content

Commit dc7daee

Browse files
authored
[C#] CodeWhisperer Code Comments - Part 7 (#159)
* Codewhisperer comments p7
1 parent da94e55 commit dc7daee

File tree

13 files changed

+89
-23
lines changed

13 files changed

+89
-23
lines changed

source/fundamentals/connection/connect.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
Connection Guide
55
================
66

7-
.. default-domain:: mongodb
7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: connection string, URI, server, Atlas, settings
813

914
.. contents:: On this page
1015
:local:
@@ -64,6 +69,8 @@ instance on port ``27017`` of ``localhost``:
6469

6570
.. literalinclude:: /includes/fundamentals/code-examples/connection/LocalConnection.cs
6671
:language: csharp
72+
:start-after: // start local connection
73+
:end-before: // end local connection
6774

6875
.. tip:: Reuse Your Client
6976

@@ -88,6 +95,8 @@ MongoDB instance on port ``27017`` of ``localhost``:
8895
.. literalinclude:: /includes/fundamentals/code-examples/connection/MongoClientSettings.cs
8996
:language: csharp
9097
:dedent:
98+
:start-after: // start mongo client settings
99+
:end-before: // end mongo client settings
91100

92101
Other Connection Targets
93102
------------------------
@@ -115,6 +124,8 @@ deployment and verify that the connection is successful:
115124

116125
.. literalinclude:: /includes/fundamentals/code-examples/connection/AtlasConnection.cs
117126
:language: csharp
127+
:start-after: // start atlas connection
128+
:end-before: // end atlas connection
118129

119130
.. tip::
120131

@@ -141,3 +152,5 @@ hosts, including ``sample.host1``:
141152

142153
.. literalinclude:: /includes/fundamentals/code-examples/connection/ReplicaSetConnection.cs
143154
:language: csharp
155+
:start-after: // start replica set connection
156+
:end-before: // end replica set connection

source/fundamentals/connection/connection-options.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
Connection Options
55
==================
66

7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: connection string, URI, server, Atlas, settings, configure
13+
714
.. contents:: On this page
815
:local:
916
:backlinks: none
@@ -28,6 +35,8 @@ and the ``tls`` option with a value of ``true``:
2835
.. literalinclude:: /includes/fundamentals/code-examples/connection/LocalConnectionConfig.cs
2936
:language: csharp
3037
:dedent:
38+
:start-after: // start local connection config
39+
:end-before: // end local connection config
3140

3241
.. _csharp-mongo-client-settings:
3342

@@ -46,6 +55,8 @@ its properties, and pass it as an argument to the ``MongoClient`` constructor:
4655
.. literalinclude:: /includes/fundamentals/code-examples/connection/MongoClientSettingsConfig.cs
4756
:language: csharp
4857
:dedent:
58+
:start-after: // start mongo client settings config
59+
:end-before: // end mongo client settings config
4960

5061
Connection Options
5162
------------------

source/fundamentals/crud/read-operations/count.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ The following example performs the following actions:
219219
:language: none
220220
:visible: false
221221

222-
Number of documents with a final grade more than 80: 2
222+
Number of documents with a final grade more than 80: 4
223223

224224

225225
Additional Information

source/includes/fundamentals/code-examples/Bson.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Modifies a BSON document by using the C# driver
2+
13
using MongoDB.Driver;
24

35
namespace DataFormats.Bson;
@@ -6,6 +8,8 @@ public class Bson
68
{
79
public static void Main(string[] args)
810
{
11+
// Creates a new document, adds "restaurant_id" field, removes the
12+
// "cuisine" field and sets the "name" value
913
//start-create
1014
var newRestaurant = new BsonDocument
1115
{

source/includes/fundamentals/code-examples/CountDocuments.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Counts the number of documents in a collection and after
2+
// applying a filter by using the C# driver
3+
14
using MongoDB.Bson.Serialization.Conventions;
25
using MongoDB.Driver;
36
namespace TestRun.Fundamentals;
@@ -10,17 +13,20 @@ public static void Main(string[] args)
1013
Setup();
1114
InsertSampleData();
1215

16+
// Finds and counts all documents with a "finalGrade" value less than 80
1317
// start-accurate-ct
1418
var filter = Builders<Student>.Filter.Lt(s => s.FinalGrade, 80.0);
1519
var count1 = _myColl.CountDocuments(filter);
1620
Console.WriteLine("Number of documents with a final grade less than 80: " + count1);
1721
// end-accurate-ct
1822

19-
// start-est-count
23+
// Finds the total number of documents in the collection
24+
// start-est-count
2025
var count2 = _myColl.EstimatedDocumentCount();
2126
Console.WriteLine("Estimated number of documents in the students collection: " + count2);
2227
// end-est-count
2328

29+
// Finds the number of documents with a "finalGrade" value greater than 80
2430
// start-agg-count
2531
var matchStage = Builders<Student>
2632
.Filter.Gt(s => s.FinalGrade, 80);

source/includes/fundamentals/code-examples/atlas-search/AtlasSearchExamples.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Performs Atlas Search queries by using the C# driver
2+
13
using MongoDB.Bson;
24
using MongoDB.Bson.Serialization.Attributes;
35
using MongoDB.Bson.Serialization.Conventions;
@@ -14,7 +16,6 @@ public static void Main(string[] args)
1416
{
1517
Setup();
1618

17-
// Call method here to test
1819
var results = AutocompleteSearch();
1920

2021
foreach (var g in results)
@@ -25,6 +26,7 @@ public static void Main(string[] args)
2526

2627
public static List<Guitar> AutocompleteSearch()
2728
{
29+
// Finds documents with a "make" value that contains the string fragment "Gib"
2830
// start-autocomplete-search
2931
var result = guitarsCollection.Aggregate()
3032
.Search(Builders<Guitar>.Search.Autocomplete(g => g.Make, "Gib"))
@@ -36,6 +38,8 @@ public static List<Guitar> AutocompleteSearch()
3638

3739
public static List<Guitar> CompoundSearch()
3840
{
41+
// Find documents that meet multiple search criteria by using the
42+
// Compound() search function
3943
// start-compound-search
4044
var result = guitarsCollection.Aggregate()
4145
.Search(Builders<Guitar>.Search.Compound()
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Defines a template for connecting to a server through Atlas
2+
3+
// start atlas connection
14
using MongoDB.Driver;
25
using MongoDB.Bson;
36

@@ -6,14 +9,15 @@
69

710
var settings = MongoClientSettings.FromConnectionString(connectionUri);
811

9-
// Set the ServerApi field of the settings object to Stable API version 1
12+
// Sets the ServerApi field of the settings object to Stable API version 1
1013
settings.ServerApi = new ServerApi(ServerApiVersion.V1);
1114

12-
// Create a new client and connect to the server
15+
// Creates a new client and connects to the server
1316
var client = new MongoClient(settings);
1417

15-
// Send a ping to confirm a successful connection
18+
// Sends a ping to confirm a successful connection
1619
try {
1720
var result = client.GetDatabase("admin").RunCommand<BsonDocument>(new BsonDocument("ping", 1));
1821
Console.WriteLine("Pinged your deployment. You successfully connected to MongoDB!");
1922
} catch (Exception ex) { Console.WriteLine(ex);}
23+
// end atlas connection
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
// Defines a template for connecting to a server by using a URI
2+
3+
// start local connection
14
using MongoDB.Driver;
25

3-
// Connection URI
6+
// Sets the connection URI
47
const string connectionUri = "mongodb://localhost:27017";
58

6-
// Create a new client and connect to the server
7-
var client = new MongoClient(connectionUri);
9+
// Creates a new client and connects to the server
10+
var client = new MongoClient(connectionUri);
11+
// end local connection
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
// Connects to a server by using a URI with configuration options
2+
3+
// start local connection config
14
using MongoDB.Driver;
25

3-
// Connection URI
6+
// Sets the connection URI
47
const string connectionUri = "mongodb+srv://sample.host:27017/?connectTimeoutMS=60000&tls=true";
58

6-
// Create a new client and connect to the server
7-
var client = new MongoClient(connectionUri);
9+
// Creates a new client and connects to the server
10+
var client = new MongoClient(connectionUri);
11+
// end local connection config
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
// Defines a MongoClientSettings object to pass settings to the client
2+
3+
// start mongo client settings
14
using MongoDB.Driver;
25

3-
// Create a MongoClientSettings object
6+
// Creates a MongoClientSettings object
47
var settings = new MongoClientSettings()
58
{
69
Scheme = ConnectionStringScheme.MongoDB,
710
Server = new MongoServerAddress("localhost", 27017)
811
};
912

10-
// Create a new client and connect to the server
11-
var client = new MongoClient(settings);
13+
// Creates a new client and connects to the server
14+
var client = new MongoClient(settings);
15+
// end mongo client settings

0 commit comments

Comments
 (0)