diff --git a/source/includes/code-examples/GradeEntry.cs b/source/includes/code-examples/GradeEntry.cs index 851ffb37..b9a4df2f 100644 --- a/source/includes/code-examples/GradeEntry.cs +++ b/source/includes/code-examples/GradeEntry.cs @@ -4,5 +4,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } \ No newline at end of file diff --git a/source/includes/code-examples/delete-many/DeleteMany.cs b/source/includes/code-examples/delete-many/DeleteMany.cs index e26ec8da..fa0daafd 100644 --- a/source/includes/code-examples/delete-many/DeleteMany.cs +++ b/source/includes/code-examples/delete-many/DeleteMany.cs @@ -1,3 +1,7 @@ +// Deletes multiple documents from a collection by using the C# driver + +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Conventions; using MongoDB.Driver; @@ -92,5 +96,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/delete-many/DeleteManyAsync.cs b/source/includes/code-examples/delete-many/DeleteManyAsync.cs index da88a883..d9bee98f 100644 --- a/source/includes/code-examples/delete-many/DeleteManyAsync.cs +++ b/source/includes/code-examples/delete-many/DeleteManyAsync.cs @@ -1,3 +1,7 @@ +// Asynchronously deletes multiple documents from a collection by using the C# driver + +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Conventions; using MongoDB.Driver; @@ -24,8 +28,6 @@ public static async Task Main(string[] args) Console.WriteLine($"Deleted documents: {result.DeletedCount}"); Restore(docs); - - return result; } private static async Task DeleteMultipleRestaurantsBuilderAsync() @@ -94,5 +96,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/delete-one/DeleteOne.cs b/source/includes/code-examples/delete-one/DeleteOne.cs index 85c7bf0a..c884bf2c 100644 --- a/source/includes/code-examples/delete-one/DeleteOne.cs +++ b/source/includes/code-examples/delete-one/DeleteOne.cs @@ -1,3 +1,7 @@ +// Deletes a document from a collection by using the C# driver + +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Conventions; using MongoDB.Driver; @@ -91,5 +95,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/delete-one/DeleteOneAsync.cs b/source/includes/code-examples/delete-one/DeleteOneAsync.cs index 6f5b2734..3426e3d8 100644 --- a/source/includes/code-examples/delete-one/DeleteOneAsync.cs +++ b/source/includes/code-examples/delete-one/DeleteOneAsync.cs @@ -1,3 +1,7 @@ +// Asynchronously deletes a document from a collection by using the C# driver + +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Conventions; using MongoDB.Driver; @@ -91,5 +95,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/find-many/FindMany.cs b/source/includes/code-examples/find-many/FindMany.cs index c7ff8926..69f032eb 100644 --- a/source/includes/code-examples/find-many/FindMany.cs +++ b/source/includes/code-examples/find-many/FindMany.cs @@ -1,4 +1,8 @@ +// Retrieves documents that match a query filter by using the C# driver + +using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; namespace CSharpExamples.UsageExamples.FindMany; @@ -111,5 +115,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/find-many/FindManyAsync.cs b/source/includes/code-examples/find-many/FindManyAsync.cs index 96150761..6cb1584e 100644 --- a/source/includes/code-examples/find-many/FindManyAsync.cs +++ b/source/includes/code-examples/find-many/FindManyAsync.cs @@ -1,4 +1,8 @@ +// Asynchronously retrieves documents that match a query filter by using the C# driver + +using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; using MongoDB.Driver.Linq; @@ -112,5 +116,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/find-one/FindOne.cs b/source/includes/code-examples/find-one/FindOne.cs index dfed8220..722c4e22 100644 --- a/source/includes/code-examples/find-one/FindOne.cs +++ b/source/includes/code-examples/find-one/FindOne.cs @@ -1,5 +1,6 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; namespace CSharpExamples.UsageExamples.FindOne; @@ -97,5 +98,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/find-one/FindOneAsync.cs b/source/includes/code-examples/find-one/FindOneAsync.cs index 88d1b51b..98d3113f 100644 --- a/source/includes/code-examples/find-one/FindOneAsync.cs +++ b/source/includes/code-examples/find-one/FindOneAsync.cs @@ -1,5 +1,6 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; using MongoDB.Driver.Linq; @@ -96,5 +97,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/insert-many/InsertMany.cs b/source/includes/code-examples/insert-many/InsertMany.cs index 427cbffe..64d070c5 100644 --- a/source/includes/code-examples/insert-many/InsertMany.cs +++ b/source/includes/code-examples/insert-many/InsertMany.cs @@ -1,5 +1,6 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; namespace CSharpExamples.UsageExamples.InsertMany; @@ -71,10 +72,10 @@ private static List GenerateDocuments() Name = "Mongo's Pizza", RestaurantId = $"12345-{i}", Cuisine = "Pizza", - Address = new BsonDocument + Address = new() { - {"street", "Pizza St"}, - {"zipcode", "10003"} + Street = "Pizza St", + ZipCode = "10003" }, Borough = "Manhattan", }; @@ -131,5 +132,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/insert-many/InsertManyAsync.cs b/source/includes/code-examples/insert-many/InsertManyAsync.cs index cc36e39f..8b67cdfd 100644 --- a/source/includes/code-examples/insert-many/InsertManyAsync.cs +++ b/source/includes/code-examples/insert-many/InsertManyAsync.cs @@ -1,5 +1,6 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; namespace CSharpExamples.UsageExamples.InsertMany; @@ -71,10 +72,10 @@ private static List GenerateDocuments() Name = "Mongo's Pizza", RestaurantId = $"12345-{i}", Cuisine = "Pizza", - Address = new BsonDocument + Address = new() { - {"street", "Pizza St"}, - {"zipcode", "10003"} + Street = "Pizza St", + ZipCode = "10003" }, Borough = "Manhattan", }; @@ -131,5 +132,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/insert-one/InsertOne.cs b/source/includes/code-examples/insert-one/InsertOne.cs index d0e9b37b..5d671f06 100644 --- a/source/includes/code-examples/insert-one/InsertOne.cs +++ b/source/includes/code-examples/insert-one/InsertOne.cs @@ -1,5 +1,6 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; namespace CsharpExamples.UsageExamples.InsertOne; @@ -38,10 +39,10 @@ private static void InsertOneRestaurant() Name = "Mongo's Pizza", RestaurantId = "12345", Cuisine = "Pizza", - Address = new BsonDocument + Address = new() { - {"street", "Pizza St"}, - {"zipcode", "10003"} + Street = "Pizza St", + ZipCode = "10003" }, Borough = "Manhattan", }; @@ -108,5 +109,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/insert-one/InsertOneAsync.cs b/source/includes/code-examples/insert-one/InsertOneAsync.cs index c6a93ba0..c0c4477d 100644 --- a/source/includes/code-examples/insert-one/InsertOneAsync.cs +++ b/source/includes/code-examples/insert-one/InsertOneAsync.cs @@ -1,5 +1,6 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; namespace CsharpExamples.UsageExamples.InsertOne; @@ -38,10 +39,10 @@ private static async Task InsertOneRestaurantAsync() Name = "Mongo's Pizza", RestaurantId = "12345", Cuisine = "Pizza", - Address = new BsonDocument + Address = new() { - {"street", "Pizza St"}, - {"zipcode", "10003"} + Street = "Pizza St", + ZipCode = "10003" }, Borough = "Manhattan", }; @@ -108,5 +109,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/replace-one/ReplaceOne.cs b/source/includes/code-examples/replace-one/ReplaceOne.cs index ca616c76..16141874 100644 --- a/source/includes/code-examples/replace-one/ReplaceOne.cs +++ b/source/includes/code-examples/replace-one/ReplaceOne.cs @@ -1,5 +1,6 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; namespace CSharpExamples.UsageExamples.ReplaceOne; @@ -48,10 +49,10 @@ private static ReplaceOneResult ReplaceOneRestaurant() Id = oldId, Name = "Mongo's Pizza", Cuisine = "Pizza", - Address = new BsonDocument + Address = new() { - {"street", "Pizza St"}, - {"zipcode", "10003"} + Street = "Pizza St", + ZipCode = "10003" }, Borough = "Manhattan", }; @@ -110,5 +111,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/replace-one/ReplaceOneAsync.cs b/source/includes/code-examples/replace-one/ReplaceOneAsync.cs index 3c187b93..7f00f978 100644 --- a/source/includes/code-examples/replace-one/ReplaceOneAsync.cs +++ b/source/includes/code-examples/replace-one/ReplaceOneAsync.cs @@ -1,5 +1,6 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; namespace CSharpExamples.UsageExamples.ReplaceOne; @@ -48,10 +49,10 @@ private static async Task ReplaceOneRestaurant() Id = oldId, Name = "Mongo's Pizza", Cuisine = "Pizza", - Address = new BsonDocument + Address = new() { - {"street", "Pizza St"}, - {"zipcode", "10003"} + Street = "Pizza St", + ZipCode = "10003" }, Borough = "Manhattan", }; @@ -110,5 +111,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/update-many/UpdateMany.cs b/source/includes/code-examples/update-many/UpdateMany.cs index 554a5298..feed52ca 100644 --- a/source/includes/code-examples/update-many/UpdateMany.cs +++ b/source/includes/code-examples/update-many/UpdateMany.cs @@ -1,4 +1,8 @@ +// Updates documents that match a query filter by using the C# driver + +using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; namespace CSharpExamples.UsageExamples.UpdateMany; @@ -41,8 +45,9 @@ private static UpdateResult UpdateManyRestaurants() const string oldValue = "Pizza"; const string newValue = "Pasta and breadsticks"; + // Creates a filter for all documents with a "cuisine" value of "Pizza" var filter = Builders.Filter - .Eq(restaurant => restaurant.Cuisine, oldValue); + .Eq(restaurant => restaurant.Cuisine, oldValue); var update = Builders.Update .Set(restaurant => restaurant.Cuisine, newValue); @@ -120,5 +125,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/update-many/UpdateManyAsync.cs b/source/includes/code-examples/update-many/UpdateManyAsync.cs index 8f178b74..7ebc02db 100644 --- a/source/includes/code-examples/update-many/UpdateManyAsync.cs +++ b/source/includes/code-examples/update-many/UpdateManyAsync.cs @@ -1,4 +1,8 @@ +// Asynchronously updates documents that match a query filter by using the C# driver + +using MongoDB.Bson; using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; namespace CSharpExamples.UsageExamples.UpdateMany; @@ -41,8 +45,9 @@ private static async Task UpdateManyRestaurantsAsync() const string oldValue = "Pizza"; const string newValue = "Pasta and breadsticks"; + // Creates a filter for all documents with a "cuisine" value of "Pizza" var filter = Builders.Filter - .Eq(restaurant => restaurant.Cuisine, oldValue); + .Eq(restaurant => restaurant.Cuisine, oldValue); var update = Builders.Update .Set(restaurant => restaurant.Cuisine, newValue); @@ -120,5 +125,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/update-one/UpdateOne.cs b/source/includes/code-examples/update-one/UpdateOne.cs index a0f769d5..83d2609a 100644 --- a/source/includes/code-examples/update-one/UpdateOne.cs +++ b/source/includes/code-examples/update-one/UpdateOne.cs @@ -1,3 +1,7 @@ +// Updates the first document that matches a query filter by using the C# driver + +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Conventions; using MongoDB.Driver; @@ -98,5 +102,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } } diff --git a/source/includes/code-examples/update-one/UpdateOneAsync.cs b/source/includes/code-examples/update-one/UpdateOneAsync.cs index c0157367..ca37c747 100644 --- a/source/includes/code-examples/update-one/UpdateOneAsync.cs +++ b/source/includes/code-examples/update-one/UpdateOneAsync.cs @@ -1,3 +1,7 @@ +// Asynchronously updates the first document that matches a query filter by using the C# driver + +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Conventions; using MongoDB.Driver; @@ -98,5 +102,5 @@ public class GradeEntry public string Grade { get; set; } - public float Score { get; set; } + public float? Score { get; set; } }