Some small summaries of MongoDB

Source: Internet
Author: User
Tags create mongodb directory create mongoclient mysql import

MongoDB installation, download the desired version of the official website, Visual Tools Mongovue (note does not support the mongodb3.0 above version)

Download MIS installation, unzip after bin, ...

1. Configure the environment variable to add the H:\mongodb\mongodbInstall\bin Bin directory to the path of the environment variable2.bin Directory Sibling directory create Data folder, new DB in Data folder, log folder under Log folder and create Mongodb.log3. Enter the following command to start the MongoDB service: (Navigate to Bin below)H:/mongodb/mongodbinstall/bin>mongod--dbpath H:\mongodb\mongodbInstall\data\dbhttp://localhost:27017 Test If the connection is successful4.data Sibling Directory creation mongodb.config Notepad open mongodb.configdbpath=h:\mongodb\mongodbinstall\data\dbLogpath=h:\mongodb\mongodbinstall\data\log\mongodb.log5. Open the cmd command line as an administrator, enter the H:/mongodb/mongodbinstall/bin directory, and enter the following command:mongod--config H:\mongodb\mongodbInstall\mongo.config--install--servicename "MongoDB"Services.msc can see that MongoDB service has been started after the MongoDB installation configuration is complete, the cmd Direct input MONGO can enter the MONGO command line, show DBS can see the existing database (I put the NS files of the previous database backup into the DB folder, show DBS when not shown) then install Mongovue (only MySQL can be imported to MongoDB for free, because there is a corresponding database for SQL Server, so conversion via SQL Server into MySQL and then import to Mongovue)sqlserver->mysql:mysql Import Wizard-"Select odbc-" Select SQL Server Native Client, Set the connection (server name (native 127.0.0.1) then SQL Server user name, password) next-"Next ...." End. Mysql->mongodb:add a database-"right-click RDBMS Import and fill in the connection."  C # connect MongoDB:   
private static string _connstr = "mongodb://127.0.0.1:27017";//private static string _connstr = "Mongodb://localhost";p R Ivate static string _dbname = "Conferencemanagement";//private static string _connstrpromote = "Mongodb://mongo:[email pr otected]:8086 ";p ublic static Mongodatabase Getmongodbcontext () {//This method is obsolete, Mongoclient.getserver replaces//return Mongoserver.create (_CONNSTR). Getdatabase (_dbname); mongoclient mc = new Mongoclient (_CONNSTR); return MC. Getserver (). Getdatabase (_dbname);}

  There is an issue of mongoclient.getserver obsolescence. With mongoclient mc = new Mongoclient (_CONNSTR);

                                       return MC. Getserver (). Getdatabase (_dbname);  Replace

Here is a demo

1   Public meetingattendrepository () 2         {3             db = mongodbcontext.getmongodbcontext (); 4         }

1  Public stringGetmeetinglist (stringpid)2         {3             Try4             {5Mongocollection col = db. Getcollection<bsondocument> ("meetingpersons");6                 varres = col. Findallas<bsondocument>();7list<bsondocument> blist =NewList<bsondocument>();8                 if(res = =NULL)9                 {Ten                     return NULL; One                 } A                 Else -                 { -                     foreach(Bsondocument KinchRes) the                     { -                         if(int. Parse (k["PersonID"]. ToString ()) = =int. Parse (PID)) -                         { -k["_id"] = k["_id"]. ToString (); + blist. ADD (k); -                         } +                     } A                     returnblist. ToJson (); at                     //return "Success"; -                 } -             } -             Catch -             { -                 return NULL; in             } -}

Some small summaries of 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.