Skip to content

kampfmodz/MongoDB-Hosting

Repository files navigation

MongoDB-Hosting

Simple Library to use MongoDB with DI. Nuget-Link

Example

DI Container

services.AddMongoService("YourMongoUri");

Collection Class

public class RandomCollection : CollectionBase<RandomModel>
{
    public RandomCollection(MongoClient client) : base(client, "Example") { }

    public async Task AddRandom(int Number)
        => await Collection.InsertOneAsync(new RandomModel(Number));

    public async Task DeleteRandom(int Number)
        => await Collection.DeleteOneAsync(filter => filter.Number == Number);
}

Collection Model

public class RandomModel
{
    [BsonId]
    public ObjectId Id { get; set; }
    public int Number { get; set; }

    public RandomModel(int Number)
    {
        this.Number = Number;
    }
}

For an working Example view MongoDB-Hosting.Example

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published