MongoDB.Thin 1.0.0

dotnet add package MongoDB.Thin --version 1.0.0                
NuGet\Install-Package MongoDB.Thin -Version 1.0.0                
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="MongoDB.Thin" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MongoDB.Thin --version 1.0.0                
#r "nuget: MongoDB.Thin, 1.0.0"                
#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 MongoDB.Thin as a Cake Addin
#addin nuget:?package=MongoDB.Thin&version=1.0.0

// Install MongoDB.Thin as a Cake Tool
#tool nuget:?package=MongoDB.Thin&version=1.0.0                

MongoDB.Thin

Thin layer over MongoDB driver for .NET. It is mostly extension methods and builders. It allows to query MongoDB more easily. The goal of this library is to stay simple, more complex cases can be built upon.

Nuget

The nuget package name is MongoDB.Thin: https://www.nuget.org/packages/MongoDB.Thin/

Usage

ASP.NET Core

To add it to ASP.NET Core

services.AddMongo("YourConnectionString", "YourDatabaseName");

Get a collection

Example where _database is an instance of IMongoDatabase. And Game is the collection holding the games.

_database.Collection<Game>();

FindOne

Get a document from a collection by supplying a filtering c# expression Example:

var game = await _games.FindOneAsync(g => g.Id == id);

FindOneAndUpdate

Get a FindOneAndUpdate command by invoking FindOneAndUpdate() on your collection (IMongoCollection<TDocument>). You can then filter it multiple times, and perform multiple modifications.

  • Filters are defined by calling Filter() on the command, the method accepts a lambda that configures the filter builder: C# filtering expression, C# expression with MongoDB operators, or a JSON string.
  • Modifications are defined by calling Modify() on the command, the method accepts a lambda that configures the modification builder. Normal MongoDB operators can be used.
  • Options can be defined by calling Options() on the command, the method accepts a lambda that configures the options builder. Projections can be defined, targeting array fields can be defined using WithArrayFilter.
  • Finally awaiting ExecuteAsync runs it asynchronously.

Example:

var command = _games.FindOneAndUpdate();
command.Filter(b => b.Match(g => g.GameType == gameType &&
		 !g.Players.Any(p => p.Id == player.Id) &&
		 g.Status == GameStatus.WaitingForPlayers));

if (duration.HasValue)
{
	command = command.Filter(b => b.Match(g => g.MaxDuration <= duration));
}

var game = await command.Update(b => b
	.Modify(g => g.Push(g => g.Players, player))
	.Modify(g => g.Inc(g => g.Version, 1)))
	.ExecuteAsync();

UpdateOne

Get an UpdateOne command by invoking UpdateOne() on your collection (IMongoCollection<TDocument>). The command is similar to FindOneAndUpdate, except that the options don't allow any projection (since no document is returned).

Indexes

Indexes can easily be added using expressions.

Example:

var db = app.ApplicationServices.GetService<IMongoDatabase>()!;

db.Collection<Game>().Indexes
	.Add(g => g.GameType)
	.Add(g => g.Status)
	.Add(g => g.Players, p => p.Id);

Here Game collection got 3 indexes:

  • GameType field ascending
  • Status field ascending
  • Players is an array, it got an index on Id field

More usage examples

You can see more usage examples in OnlineBoardz repository:

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.0.0 2,134 7/22/2020