com.adrenak.mongodb.entities.upm
v1.0.3
Published
UPM package for MongoDB.Entities. NOT updated regularly.
Downloads
7
Readme
MongoDB.Entities
This library simplifies access to mongodb by abstracting away the C# mongodb driver and providing some additional features on top of it. The API is clean and intuitive resulting in less lines of code that is more readable/ human friendly than driver code.
Advantages:
- Never have to deal with
ObjectIds
,BsonDocuments
& magic strings. - Built-in support for
One-To-One
,One-To-Many
andMany-To-Many
relationships. - Query data using LINQ, lambda expressions, filters and aggregation pipelines.
- Sorting, paging and projecting is made convenient.
- Simple data migration framework similar to EntityFramework.
- Programatically define indexes.
- Full text search (including fuzzy matching) with text indexes.
- Multi-document transaction support.
- Easy bulk operations.
- Update with aggregation pipeline stages & array filters.
- Easy GeoSpatial search.
- Stream files in chunks to and from mongodb (GridFS alternative).
- Multiple database support.
- Project types supported: .Net Standard 2.0 (.Net Core 2.0 & .Net Framework 4.6.1 or higher)
Documentation
Code Sample
//Initialize database connection
new DB("bookshop","localhost");
//Create and persist an entity
var book = new Book { Title = "The Power Of Now" };
book.Save();
//Embed as document
var dickens = new Author { Name = "Charles Dickens" };
book.Author = dickens.ToDocument();
book.Save();
//One-To-One relationship
var hemmingway = new Author { Name = "Ernest Hemmingway" };
hemmingway.Save();
book.MainAuthor = hemmingway;
book.Save();
//One-To-Many relationship
var tolle = new Author { Name = "Eckhart Tolle" };
tolle.Save();
book.Authors.Add(tolle);
//Many-To-Many relationship
var genre = new Genre { Name = "Self Help" };
genre.Save();
book.AllGenres.Add(genre);
genre.AllBooks.Add(book);
//Queries
var author = DB.Find<Author>().One("ID");
var authors = DB.Find<Author>().Many(a => a.Publisher == "Harper Collins");
var eckhart = DB.Queryable<Author>()
.Where(a => a.Name.Contains("Eckhart"))
.SingleOrDefault();
var powerofnow = genre.AllBooks.ChildrenQueryable()
.Where(b => b.Title.Contains("Power"))
.SingleOrDefault();
var selfhelp = book.AllGenres.ChildrenQueryable().First();
//Delete
book.MainAuthor.Delete();
book.AllAuthors.DeleteAll();
book.Delete();
DB.Delete<Genre>(genre.ID);
Code Examples
- .net core console project
- asp.net core web-api project
- a collection of gists
- integration/unit test project
- solutions to stackoverflow questions
Donations
if this library has made your life easier and you'd like to express your gratitude, you can donate a couple of bucks via paypal by clicking the button below: