{"id":22199272,"url":"https://github.com/pmarkert/mongol","last_synced_at":"2025-07-27T02:32:01.106Z","repository":{"id":2431143,"uuid":"3400545","full_name":"pmarkert/Mongol","owner":"pmarkert","description":"Simple Repository Pattern wrapper for the MongoDB Driver .NET ","archived":false,"fork":false,"pushed_at":"2012-05-17T20:40:28.000Z","size":892,"stargazers_count":5,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-03T01:07:26.178Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmarkert.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-09T19:49:02.000Z","updated_at":"2016-01-06T06:55:56.000Z","dependencies_parsed_at":"2022-07-16T01:48:09.430Z","dependency_job_id":null,"html_url":"https://github.com/pmarkert/Mongol","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmarkert%2FMongol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmarkert%2FMongol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmarkert%2FMongol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmarkert%2FMongol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmarkert","download_url":"https://codeload.github.com/pmarkert/Mongol/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227750210,"owners_count":17814129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T15:13:48.823Z","updated_at":"2024-12-02T15:13:50.689Z","avatar_url":"https://github.com/pmarkert.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongol Project\nWelcome! Mongol is a very simple wrapper library for 10gen's [Official MongoDB C#/.NET Driver](http://www.mongodb.org/display/DOCS/CSharp+Language+Center) that helps shortcut some repetitive tasks when building applications that use MongoDB to store documents in strongly-typed collections.\n\n## Quick Start\nThe easiest way to get started with Mongol is to\n\n1. Add Mongol to your project using [Nuget](http://docs.nuget.org/docs/start-here/managing-nuget-packages-using-the-dialog)\n2. Add the **Mongol.Url** appSetting to your application .config\n```\n\u003cappSettings\u003e\n    \u003cadd key=\"Mongol.Url\" value=\"mongodb://hostname/database\" /\u003e \n\u003c/appSettings\u003e\n```\n3. Create the classes that you wish to store and retrieve with MongoDB.  This can be done of two ways:\n    * Create your own POCO classes and add the [BsonId] attribute to your uniquely identifying field if it isn't  called Id, id, or _id.\n```\npublic class Person {\n    [BsonId]\n    public Guid PersonId { get; set; }\n    public string Name { get; set; }\n}\n```\n    * Inherit from **_Mongol.Record_** or **_Mongol.TimestampedRecord_** which already has an Id with an associated autogenerator\n```\n[BsonId(IdGenerator = typeof(StringObjectIdGenerator))]\npublic virtual string Id { get; set; }\n```\n\nNow you can create an instance of **RecordManager\\\u003cPerson\\\u003e** and go to town.  For example:\n\n```\n    var personManager = new RecordManager\u003cPerson\u003e();\n    Person person = personManager.GetById(person.Id);\n    person.Name = \"Updated Name\";\n    personManager.Save(person);\n```\n\n## What Mongol _does not_ do\n\nMongol does not promise to take out your trash or walk you dog. If it improves your marriage, then it's probably just because it saved you a few extra minutes at work. \n\nEverything that can be done with Mongol can be done directly using the 10Gen Driver.  Mongol simply wraps some of the common operations I found myself repeating and makes some of those repetitive tasks a little bit less... repetitive... :) \n\nMongol also provides some _very limited_ prescriptive guidance when starting up a new project using MongoDB. \n\n## What Mongol _does_ do\n\nMongol provides a few features on top of the MongoDB driver, all of which can be used independently of each other.  Feel free to use the features you want and ignore the rest, Mongol won't get it's feelings hurt.\n\nFeatures offered by Mongol:\n\n* A simple [Repository Pattern](http://martinfowler.com/eaaCatalog/repository.html) wrapper for MongoDB collections exposing the most common CRUD functionality for strongly typed documents \n\n```\ninternal class PersonManager : RecordManager\u003cPerson\u003e {\n    // Public methods inherited from RecordManager\u003cT\u003e\n    IQueryable\u003cT\u003e AsQueryable { get; }\n    void DeleteById(object id);\n    T GetById(object id);\n    IEnumerable\u003cT\u003e GetManyByIds(IEnumerable\u003cobject\u003e ids);\n    bool Save(T record);\n    void BatchInsert(IEnumerable\u003cT\u003e records);\n\n    // Protected methods inherited from RecordManager\u003cT\u003e\n    long Count(IMongoQuery criteria = null);\n    IEnumerable\u003cT\u003e Find(IMongoQuery criteria, IMongoSortBy sort = null, int? skip = null, int? limit = null);\n    T FindSingle(IMongoQuery criteria);\n    void Initialize(); // For once-per application runtime maintenance like Ensuring Indexes, Purging Data, Setting Conventions\n    void DropCollection();\n    T FindOneAndModify(IMongoQuery criteria, IMongoUpdate update, IMongoSortBy sortBy = null, bool returnModifiedVersion = true);\n    T FindOneAndRemove(IMongoQuery criteria, IMongoSortBy sortBy = null);\n    IEnumerable\u003cT\u003e EnumerateAndModify(IMongoQuery criteria, IMongoUpdate update, IMongoSortBy sortBy = null, bool returnModifiedVersion = true);\n    IEnumerable\u003cT\u003e EnumerateAndRemove(IMongoQuery criteria, IMongoSortBy sortBy = null);\n    long UpdateMany(IMongoQuery criteria, UpdateBuilder update, bool asUpsert = false);\n    long DeleteMany(IMongoQuery criteria);\n    void EnsureIndex(IMongoIndexKeys keys, IMongoIndexOptions options);\n}\n```\n* Lambda-based property-name resolution for building MongoDB queries without using magic strings \n\n```\npublic IEnumerable\u003cPerson\u003e GetByLastName(string LastName) {\n  // Instead of magic strings like this:\n  return Find(Query.EQ(\"LastName\", LastName));\n  // Use Lambdas for Compile-time safety like this:\n  return Find(Query.EQ(PropertyName(p =\u003e p.LastName), LastName));\n  // Also works for collection members by using .Member()\n  string ChildLastNameField = PropertyName(p.Children.Member().LastName; // Evaluates to \"Children.LastName\"\n  return Find(Query.EQ(LastNameField, LastName)); // [NOTE: Returns the parent document]\n  // You can find the relative properties on a child object (without the parent prefix) using .Relative(), useful for $elemMatch\n  string LastNameField = PropertyName(p.Children.Relative().LastName; // Evaluates to \"LastName\" (without the \"Children.\")\n}\n```\n\n* Simple connection-string configuration using a single appSetting.  Mongol now also supports multiple, named connections.\n\n```\n\u003cappSettings\u003e\n  \u003cadd key=\"Mongol.Url\" value=\"mongodb://localhost/test?safe=true\"/\u003e\n\u003c/appSettings\u003e\n```\n\n* A manager factory to encapsulate/cache construction of new repository instances\n\n```\nPersonManager personManager = ManagerFactory.GetManager\u003cPersonManager\u003e();\n```\n\n* A base-class from which strongly-typed documents can optionally inherit, providing string-typed Ids and automatic **_id** field population if saved as **null**.\n\n```\npublic class Person : Record {\n  public string FirstName { get; set; }\n  public string LastName { get; set; }\n  public Address Address { get; set; }\n  public Person[] Children { get; set; }\n}\n\n// Inherited from Record\n[BsonId(IdGenerator = typeof(StringObjectIdGenerator))]\npublic virtual string Id { get; set; }\n```\n\n* Another base-class (and interface) from which documents can inherit providing automatic maintenance of Creation/Modification timestamps.\n\n```\npublic class Person : ITimeStampedRecord {\n  #region ITimeStampedRecord Members\n  public DateTime CreatedDate { get; set; }\n  public DateTime ModifiedDate { get; set; }\n  #endregion\n}\n```\n\n* A caching record manager to cache (by Id) retrieved instances of objects (useful for lookup collections)\n\n* A set of convenience methods for interacting with MongoDB's new Aggregation Framework.\n\n```\n... class ... : RecordManager {\n\npublic Dictionary\u003cstring,int\u003e CalculateVerseCountByBook() {\n\treturn base.Aggregate(\n\t\t\tAggregation.Group(\n\t\t\t\tAggregation.Grouping.By(PropertyName(x =\u003e x.Book)), \n\t\t\t\tAggregation.Grouping.Count(\"Count\")),\n\t\t\tAggregation.Sort(Aggregation.Sorting.By(\"Count\", false))\n\t).ToDictionary(x =\u003e x[ID_FIELD].AsString, x =\u003e x[\"Count\"].AsInt32);\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmarkert%2Fmongol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmarkert%2Fmongol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmarkert%2Fmongol/lists"}