MongoDB.Repository.Core 2.0.0

MongoDB repository implementation for .net core.

Install-Package MongoDB.Repository.Core -Version 2.0.0
dotnet add package MongoDB.Repository.Core --version 2.0.0
<PackageReference Include="MongoDB.Repository.Core" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MongoDB.Repository.Core --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

MongoDB.SimpleRepository

Repository implementation for .net core MongoDB driver.

Supports

  • Any type for id, like Guid or int. ObjectId or BsonId are not required in your classes. Keep your POCO objects plain!
  • Connection pooling. Takes advantage of MongoDb.Driver's support for thread-safe static database and collection references.
  • Bulk add or delete.

Nuget package MongoDB.Repository.Core

Usage

  1. Name one of the fields "Id" in your model. It doesn't need to be an ObjectId or have Bson attributes. Any type except for a list or array will do as an Id.
    public class Record
    {
        public Guid Id {get; set;}
        public string Name { get; set; }
    }
  1. Your repository. Takes two type parameters--the type of your record and the type of the Id--and then your connection string.
    var repo = new Repository<Record, Guid>(connectionString);

Examples

FindById:

    var record = await repo.FindByIdAsync(new Guid("134c24bf-e1c8-4ec9-bd7e-ebbe211ebb72"));

Upsert accepts an optional IEqualityComparer, which will test whether there are actually any changes between the record to upsert and the existing record. This can greatly improve speed, since it only writes when it needs to.

    public class RecordComparer : IEqualityComparer<Record>
    {
        public bool Equals(Record x, Record y)
        {
            if (x == null && y == null) return true;
            if (x == null || y == null) return false;

            return x.Name == y.Name;
        }

        public int GetHashCode(Record obj)
        {
            return obj.Name?.GetHashCode() ?? 0;
        }
    }
    
    //Implementation
    repo.Upsert(myRecord, new RecordComparer());

MongoDB.SimpleRepository

Repository implementation for .net core MongoDB driver.

Supports

  • Any type for id, like Guid or int. ObjectId or BsonId are not required in your classes. Keep your POCO objects plain!
  • Connection pooling. Takes advantage of MongoDb.Driver's support for thread-safe static database and collection references.
  • Bulk add or delete.

Nuget package MongoDB.Repository.Core

Usage

  1. Name one of the fields "Id" in your model. It doesn't need to be an ObjectId or have Bson attributes. Any type except for a list or array will do as an Id.
    public class Record
    {
        public Guid Id {get; set;}
        public string Name { get; set; }
    }
  1. Your repository. Takes two type parameters--the type of your record and the type of the Id--and then your connection string.
    var repo = new Repository<Record, Guid>(connectionString);

Examples

FindById:

    var record = await repo.FindByIdAsync(new Guid("134c24bf-e1c8-4ec9-bd7e-ebbe211ebb72"));

Upsert accepts an optional IEqualityComparer, which will test whether there are actually any changes between the record to upsert and the existing record. This can greatly improve speed, since it only writes when it needs to.

    public class RecordComparer : IEqualityComparer<Record>
    {
        public bool Equals(Record x, Record y)
        {
            if (x == null && y == null) return true;
            if (x == null || y == null) return false;

            return x.Name == y.Name;
        }

        public int GetHashCode(Record obj)
        {
            return obj.Name?.GetHashCode() ?? 0;
        }
    }
    
    //Implementation
    repo.Upsert(myRecord, new RecordComparer());

Release Notes

Version 2 supports faster upserts and synchronous methods.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.0 157 9/20/2018
1.0.1 122 9/17/2018
1.0.0 121 9/16/2018