The. NET core can also use MongoDB

Source: Internet
Author: User
Tags mongoclient

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.