MongoDB Learning Notes (i)

Source: Internet
Author: User
Tags log log mongodb download

    • MongoDB Download Path: http://www.mongodb.org/downloads
    • Installation method:

For example here I save to D:\MongoDB\, and run cmd as an administrator, and then copy this code into C:\windows\system32>mongod--logpath D:\MongoDB\Logs\ MongoDBLogs.log--logappend--dbpath D:\MongoDB\data\db--directoryperdb--servicename MongoDB--install, then enter, This allows the MongoDB database to be installed, and starting the database requires running the following code: C:\windows\system32>net start MongoDB.
Installation Properties Description:
--logpath D:\MongoDB\Logs\MongoDBLogs.log Log path configuration (Logs directory needs to be established in advance)
--logappend logs are saved in Append mode
--dbpath D:\MongoDB\DataBase Database File save path
--directoryperdb setting each database will be stored in a separate directory
--servicename MongoDB setting up MongoDB as the name of the system service
--install Installation

    • Win8 system to run CMD as Administrator
    • How to connect Mangodb with Java?

Download Mongo-2.10.1.jar, new Java project, import jar package, write program test:

 Packagecn.lcw.mongo.db;Importjava.net.UnknownHostException;ImportJava.util.Iterator;ImportJava.util.Set;ImportCom.mongodb.DB;Importcom.mongodb.DBCollection;ImportCom.mongodb.Mongo;Importcom.mongodb.MongoException; Public classConnecttomangodb { Public Static voidMain (string[] args)throwsException {Mongo m=NULL; DB DB=NULL; Try {              //Mongo (p1, p2):p 1=>ip address p2=> Portm =NewMongo ("127.0.0.1", 27017); //get MongoDB objects based on the name of the MongoDB databasedb = M.getdb ("TESTLCW"); //verifying that the user's password is correct            if(!db.authenticate ("LCW", "LCW". ToCharArray ())) {System.out.println ("Connect MongoDB database, checksum failed!" "); }Else{System.out.println ("Connect MongoDB database, verify success!" ");                  Db.requeststart (); //Get collection nameSet<string> Colnameset =Db.getcollectionnames (); Iterator<String> Colnameitr =Colnameset.iterator ();  while(Colnameitr.hasnext ()) {String colname=Colnameitr.next (); System.out.println ("Name of the data collection:" +colname); }                  //Get Collection ObjectDbcollection Dbcol = db.getcollection ("ADMIN1352528239201"); if(Dbcol! =NULL){                      //Get collection SizeInteger colsize = (integer) dbcol.getstats (). Get ("Size"); System.out.println ("DataSet size is [unit: B]:" +colsize);              } db.requestdone (); }          } Catch(unknownhostexception e) {e.printstacktrace (); } Catch(mongoexception e) {e.printstacktrace (); }          //MongoDB Connection off        finally{              if(NULL!=m) {if(NULL!=db) {                      //to end a transaction request for the MONGO database                    Try{db.requestdone (); } Catch(Exception e) {e.printstacktrace (); }                  }                  Try{m.close (); } Catch(Exception E1) {e1.printstacktrace (); } m=NULL; }          }      }  }  

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.