- 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; } } } }