Setup MongoDB

1.  MongoDB is self-contained and does not have any other system dependencies. You can run MongoDB from any folder you choose. You may install MongoDB in any directory.

2.  MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is C:\data\db . You may specify an alternate path with the dbpath setting for mongod.ext:
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data

3.  To start MongoDB, execute bin\mongod.exe . Do not make mongod.exe accessible to public networks without running in “Secure Mode” on a public network. Usually, MongoDB runs in “trusted environments” and the database does not enable authentication or “Secure Mode” by default.

4.  To connect to MongoDB using the bin\mongo.exe . This mongo shell will connect to the database running on the localhost interface and port 27017 by default. And the mongoDB by default has a “test ” database.

5.  You can pass mongo an optional argument specifying the address, port and even the database to initially connect to:  

./mongo foo #connects to the foo database on your local machine
./mongo 192.168.13.7/foo #connects to the foo database on 192.168.13.7
./mongo dbserver.mydomain.com/foo #connects to the foo database on dbserver.mydomain.com
./mongo 192.168.13.7:9999/foo #connects to the foo database on 192.168.13.7 on port 9999
 


6.  When the shell is launched, it checks the user's home directory for a javascript file named mongorc.js . If this file is found, its contents are interpreted and run by the shell prior to displaying the prompt for the first time. This allows the user to define variables, customize the prompt, or update information that they would like updated every time they launch a shell. This functionality can be overridden with the --norc flag. It should be noted that if a file is specified to be executed by the shell, the rc file will not be run until after that file has completed.

7.  You should set up a configuration file when running MongoDB as a Windows Service:
echo logpath=C:\mongodb\log > C:\mongodb\mongod.cfg

Consider setting the logappend option, otherwise, mongod.exe will delete the contents of the existing log file when starting. To install the MongoDB service:
C:\mongodb\bin\mongod.exe --config C:\mongodb\mongod.cfg --install

For the --install option to succeed, you must specify a logpath setting or the --logpath run-time option. To remove MongoDB Service:
C:\mongodb\bin\mongod.exe --remove

猜你喜欢

转载自seanzhou.iteye.com/blog/1571386