TK.MongoDB.GridFS.Repository 2.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package TK.MongoDB.GridFS.Repository --version 2.0.2                
NuGet\Install-Package TK.MongoDB.GridFS.Repository -Version 2.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TK.MongoDB.GridFS.Repository" Version="2.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TK.MongoDB.GridFS.Repository --version 2.0.2                
#r "nuget: TK.MongoDB.GridFS.Repository, 2.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TK.MongoDB.GridFS.Repository as a Cake Addin
#addin nuget:?package=TK.MongoDB.GridFS.Repository&version=2.0.2

// Install TK.MongoDB.GridFS.Repository as a Cake Tool
#tool nuget:?package=TK.MongoDB.GridFS.Repository&version=2.0.2                

TK.MongoDB.GridFS.Repository

Repository pattern implementation of MongoDB GridFS in .NET Framework

Usage

Settings
  1. Default BucketChunkSizeBytes is set to 2097152 bytes or 2 MiB, but you can configure this by calling a static method as below:

    Settings.Configure(2097152);
    
  2. Default ConnectionStringSettingName is set to "MongoDocConnection", but you can configure this by calling a static method as below:

    Settings.Configure(connectionStringSettingName: "MongoDocConnection");
    
  3. You can also set both of the settings as below:

    Settings.Configure(2097152, "MongoDocConnection");
    
Models

Create a document model implementing $BaseFile$ to use in repository. The name of this model will be used as bucket name in MongoDB.

public class Image : BaseFile<ObjectId>
{
    public bool isDisplay { get; set; }
}
Repository methods
  1. Get (by Filter Definition)

    //Search filters
    var filter = Builders<GridFSFileInfo<ObjectId>>.Filter.And(
                    Builders<GridFSFileInfo<ObjectId>>.Filter.Eq(x => x.Filename, "securityvideo"),
                    Builders<GridFSFileInfo<ObjectId>>.Filter.Gte(x => x.UploadDateTime, new DateTime(2015, 1, 1, 0, 0, 0, DateTimeKind.Utc)),
                    Builders<GridFSFileInfo<ObjectId>>.Filter.Lt(x => x.UploadDateTime, new DateTime(2015, 2, 1, 0, 0, 0, DateTimeKind.Utc)));
    
    var sort = Builders<GridFSFileInfo>.Sort.Descending(x => x.UploadDateTime);
    var options = new GridFSFindOptions
    {
        Limit = 1,
        Sort = sort
    };
    
    IEnumerable<Image> files = imgRepository.Get(filter, options);
    
  2. Get (by Id)

    Image file = imgRepository.Get(new ObjectId("5e36b5a698d2c14fe8b0ecbe"));
    
  3. Get (by Filename)

    IEnumerable<Image> files = imgRepository.Get("Omega1.png");
    
  4. Insert

    byte[] fileContent = File.ReadAllBytes("../../Files/Omega.png");
    
    Image img = new Image()
    {
        Filename = "Omega.png",
        Content = fileContent,
        isDisplay = false
    };
    
    string id = imgRepository.Insert(img);
    
  5. Delete

    imgRepository.Delete(new ObjectId("5e36b5a698d2c14fe8b0ecbe"));
    
Tests

Refer to TK.MongoDB.GridFS.Test project for all Unit Tests.

Product Compatible and additional computed target framework versions.
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.7 1,624 10/28/2022
2.1.6 738 1/17/2022
2.1.5 925 8/3/2021
2.1.5-rc1 264 8/2/2021
2.1.4 492 4/12/2021
2.1.3 1,202 9/1/2020
2.1.2 575 8/19/2020
2.1.1 477 8/18/2020
2.0.6 1,085 2/20/2020
2.0.5 530 2/6/2020
2.0.4 524 2/6/2020
2.0.3 496 2/3/2020
2.0.2 491 2/2/2020

Initial release