Getting Started with C # and MongoDB

Source: Internet
Author: User
Tags windows x64

MongoDB website
https://www.mongodb.com/

MongoDB default installation path (Windows x64 platform)
C:\Program Files\mongodb\server\3.4\bin

MONGODB environment variable Configuration

Start MongoDB Service
> Mongod-dbpath D:\mongodb
> MONGO

Visual Studio References MongoDB
Pm> Install-package Mongodb.driver

C # operations See
https://docs.mongodb.com/ecosystem/drivers/csharp/

 String url = "mongodb://127.0.0.1:27017"; var client = new Mongoclient (URL); var db = client. Getdatabase ("blog");//Get the database and create a var collection = db If it does not exist. Getcollection<post> ("Post");  Increment//for (int i = 1; i < 10000; i++) {//Post post = new post ()//{//Id = i,//Author = "Author" + I,//Createtime = DateTime.Now,//Issue = False,//Title = "ARTICLE" + I,//Details = Guid.new Guid (). ToString (),///Comments = new list<string> () {"Comment" + i}//}; Collection. Insertone (POST); }//Check//Console.WriteLine (collection. Countdocuments (c = 1 = = 1)); var P5 = collection. Find (p = = P.id = 5). First (); Console.WriteLine ("{0} published {2}" in {1}, P5. Author, P5. Createtime, P5. Title); Delete//collection. Findoneanddelete<post> (p = p.id = = 6); var P6 = collection. Find<post> (p = p.id = = 6). FirstOrDefault (); Change//var filter = Builders<post>. Filter.eq ("Id", 7); var update = builders<post>. Update.set ("Title", "Summer"); Collection. Findoneandupdate<post> (filter, update); var P7 = collection. Find (f = f.id = = 7). FirstOrDefault (); Console.WriteLine ("{0} published {2}" in {1}, P7. Author, P7. Createtime, P7. Title);

Configuring MongoDB Services
Create the profile mongod.cfg in the MongoDB installation directory, and then add the output path of the service log to the configuration file (there is no mandatory requirement for the path)

systemLog:    destination: file    path: D:\mongodb\logs\mongodb.logstorage:    dbPath: D:\mongodb\data

Open Cmd.exe by admin
>mongod--config "D:\mongoDB\mongod.cfg"--install--servicename "MongoDB"

Getting Started with C # and 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.