Perhaps because. NET core is not yet the official version of it, MongoDB's official driver (http://mongodb.github.io/mongo-csharp-driver/) has not supported. NET core, which gives you the desire to Try MongoDB on the core is inconvenient, I am one of them:)
So fork the official source code, not too many changes, you can run, so packed and released, dare not exclusive!
You can find this package on NuGet by searching for "RaisingStudio.MongoDB.Driver", or you can install it directly from the Packages Management console:
Install-package RaisingStudio.MongoDB.Driver
Example:
using Mongodb.bson; using Mongodb.driver;
varClient =NewMongoclient ("mongodb://localhost:27017");varDatabase = client. Getdatabase ("Foo");varCollection = database. Getcollection<bsondocument> ("Bar");awaitCollection. Insertoneasync (NewBsondocument ("Name","Jack"));varList =awaitCollection. Find (NewBsondocument ("Name","Jack")) . Tolistasync ();foreach(varDocumentinchlist) {Console.WriteLine (document["Name"]);}
Or use a strongly typed method:
Public class person{ publicgetset;} Public string Get Set ; }}
varClient =NewMongoclient ("mongodb://localhost:27017");varDatabase = client. Getdatabase ("Foo");varCollection = database. Getcollection<person> ("Bar");awaitCollection. Insertoneasync (Newperson {Name ="Jack" });varList =awaitCollection. Find (x = X.name = ="Jack") . Tolistasync ();foreach(varPersoninchlist) {Console.WriteLine (person. Name);}
For more information, see the official documentation:
http://mongodb.github.io/mongo-csharp-driver/
Source:
Https://github.com/zhongzf/mongo-csharp-driver
The. NET core can also use MongoDB