diff --git a/.gitignore b/.gitignore index dfcfd56..b67693e 100644 --- a/.gitignore +++ b/.gitignore @@ -348,3 +348,6 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ + +# Rider +.idea/ \ No newline at end of file diff --git a/AtlasStarter/AtlasStarter.csproj b/AtlasStarter/AtlasStarter.csproj index 3951b57..9556ec1 100644 --- a/AtlasStarter/AtlasStarter.csproj +++ b/AtlasStarter/AtlasStarter.csproj @@ -1,71 +1,19 @@ - - + - Debug - anycpu - {AF9123AE-E6AF-44F6-BBE6-D8A633C4FDDE} + net6.0 Exe - AtlasStarter - AtlasStarter - v4.7.2 + false - true - full - false bin\Debug DEBUG; - prompt - 4 true - true bin\Release - prompt - 4 true - - - packages\Crc32C.NET.1.0.5.0\lib\net20\Crc32C.NET.dll - - - packages\MongoDB.Bson.2.10.4\lib\net452\MongoDB.Bson.dll - - - packages\MongoDB.Libmongocrypt.1.0.0\lib\net452\MongoDB.Libmongocrypt.dll - - - packages\SharpCompress.0.23.0\lib\net45\SharpCompress.dll - - - packages\Snappy.NET.1.1.1.8\lib\net45\Snappy.NET.dll - - - packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll - - - packages\DnsClient.1.3.1\lib\net471\DnsClient.dll - - - packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll - - - packages\MongoDB.Driver.Core.2.10.4\lib\net452\MongoDB.Driver.Core.dll - - - packages\MongoDB.Driver.2.10.4\lib\net452\MongoDB.Driver.dll - + - - - - - - - - - \ No newline at end of file diff --git a/AtlasStarter/Models/Recipe.cs b/AtlasStarter/Models/Recipe.cs new file mode 100644 index 0000000..db9d5f0 --- /dev/null +++ b/AtlasStarter/Models/Recipe.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using MongoDB.Bson.Serialization.Attributes; + +namespace AtlasStarter.Models; + +/// +/// This Recipe class provides formal C# code structure to the data +/// that is stored in MongoDB. Using strongly-typed classes makes +/// serialization & deserializaton of your data much easier. +/// + +[BsonIgnoreExtraElements] +public class Recipe +{ + public string Name { get; set; } + public List Ingredients { get; set; } + public int PrepTimeInMinutes { get; set; } + + public Recipe(string name, List ingredients, int prepTime) + { + Name = name; + Ingredients = ingredients; + PrepTimeInMinutes = prepTime; + } + + /// + /// This static method is just here so we have a convenient way + /// to generate sample recipe data. + /// + /// A list of Recipes + public static List GetRecipes() + { + return new List + { + new("elotes", new List(){"corn", "mayonnaise", "cotija cheese", "sour cream", "lime" }, 35), + new("loco moco", new List(){"ground beef", "butter", "onion", "egg", "bread bun", "mushrooms" }, 54), + new("patatas bravas", new List(){"potato", "tomato", "olive oil", "onion", "garlic", "paprika" }, 80), + new("fried rice", new List(){"rice", "soy sauce", "egg", "onion", "pea", "carrot", "sesame oil" }, 40), + }; + } +} \ No newline at end of file diff --git a/AtlasStarter/Program.cs b/AtlasStarter/Program.cs index a071ee3..6c1aa15 100644 --- a/AtlasStarter/Program.cs +++ b/AtlasStarter/Program.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; +using AtlasStarter.Models; using MongoDB.Driver; namespace AtlasStarter { - class MainClassNoPrompt + static class MainClassNoPrompt { public static void Main(string[] args) { @@ -55,8 +56,9 @@ public static void Main(string[] args) var dbName = "myDatabase"; var collectionName = "recipes"; - collection = client.GetDatabase(dbName) - .GetCollection(collectionName); + collection = client + .GetDatabase(dbName) + .GetCollection(collectionName); /* *** INSERT DOCUMENTS *** * @@ -88,10 +90,11 @@ public static void Main(string[] args) * filters, and is used here to show its most basic use. */ - var allDocs = collection.Find(Builders.Filter.Empty) + var allDocs = collection + .Find(Builders.Filter.Empty) .ToList(); - foreach (Recipe recipe in allDocs) + foreach (var recipe in allDocs) { Console.WriteLine($"{recipe.Name} has {recipe.Ingredients.Count} ingredients " + $"and takes {recipe.PrepTimeInMinutes} minutes to make"); @@ -103,11 +106,12 @@ public static void Main(string[] args) // use the Builders class to create the filter, and a LINQ // statement to define the property and value we're after: - var findFilter = Builders - .Filter.AnyEq(t => t.Ingredients, - "potato"); + var findFilter = Builders.Filter + .AnyEq(t => t.Ingredients, "potato"); - var findResult = collection.Find(findFilter).FirstOrDefault(); + var findResult = collection + .Find(findFilter) + .FirstOrDefault(); if (findResult == null) { @@ -128,7 +132,8 @@ public static void Main(string[] args) * just found. */ - var updateFilter = Builders.Update.Set(t => t.PrepTimeInMinutes, 72); + var updateFilter = Builders.Update + .Set(t => t.PrepTimeInMinutes, 72); // The following FindOneAndUpdateOptions specify that we want the *updated* document // to be returned to us. By default, we get the document as it was *before* @@ -147,6 +152,7 @@ public static void Main(string[] args) Console.WriteLine("Here's the updated document:"); Console.WriteLine(updatedDocument.ToString()); Console.WriteLine(); + /* *** DELETE DOCUMENTS *** * * As with other CRUD methods, you can delete a single document @@ -157,49 +163,13 @@ public static void Main(string[] args) */ var deleteResult = collection - .DeleteMany(Builders.Filter.In(r => r.Name, new string[] { "elotes", "fried rice" })); + .DeleteMany(Builders.Filter.In(r => r.Name, new[] { "elotes", "fried rice" })); Console.WriteLine($"I deleted {deleteResult.DeletedCount} records."); Console.Read(); } } - - /// - /// This Recipe class provides formal C# code structure to the data - /// that is stored in MongoDB. Using strongly-typed classes makes - /// serialization & deserializaton of your data much easier. - /// - - public class Recipe - { - public string Name { get; set; } - public List Ingredients { get; set; } - public int PrepTimeInMinutes { get; set; } - - public Recipe(string name, List ingredients, int prepTime) - { - this.Name = name; - this.Ingredients = ingredients; - this.PrepTimeInMinutes = prepTime; - } - - /// - /// This static method is just here so we have a convenient way - /// to generate sample recipe data. - /// - /// A list of Recipes - public static List GetRecipes() - { - return new List() - { - new Recipe("elotes", new List(){"corn", "mayonnaise", "cotija cheese", "sour cream", "lime" }, 35), - new Recipe("loco moco", new List(){"ground beef", "butter", "onion", "egg", "bread bun", "mushrooms" }, 54), - new Recipe("patatas bravas", new List(){"potato", "tomato", "olive oil", "onion", "garlic", "paprika" }, 80), - new Recipe("fried rice", new List(){"rice", "soy sauce", "egg", "onion", "pea", "carrot", "sesame oil" }, 40), - }; - } - } } diff --git a/AtlasStarter/Properties/AssemblyInfo.cs b/AtlasStarter/Properties/AssemblyInfo.cs index 0bb6866..abe5837 100644 --- a/AtlasStarter/Properties/AssemblyInfo.cs +++ b/AtlasStarter/Properties/AssemblyInfo.cs @@ -17,7 +17,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. diff --git a/AtlasStarter/packages.config b/AtlasStarter/packages.config deleted file mode 100644 index 4efb5b2..0000000 --- a/AtlasStarter/packages.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file