MongoDB deployment experiment series articles, MongoDB, as a NoSQL database, has continued to heat up in recent years, and more and more companies have begun to try to use MongoDB instead of the original Database to do some things. MongoDB also performs quite well in clustering, sharding, and replication. I will introduce by doing various MongoDB deployment experiments.
Preface
As a document-based NoSQL database, MongoDB is very flexible to use and avoids the complex database design of relational databases in the early stage. MongoDB storage is based on the JSON format, and Javascript is used as the database operation language, which gives users unlimited imagination. They can solve very complex conditional query problems in the MongoDB server through programming.
Directory
MongoDB installation in Windows
MongoDB installation in Linux Ubuntu
Access MongoDB through the command line client
1 MongoDB is installed in Windows
It is very simple to install the MongoDB database on the Windows system. Download the executable installation file (exe) and double-click to install it. Download link: http://www.mongodb.org/downloads
MongoDB server running command: MongoDB installation directory/bin/mongod.exe
MongoDB client run command: MongoDB installation directory/bin/mongo.exe
2 MongoDB is installed in Linux Ubuntu
The Linux used in this article is Ubuntu 12.04.2 LTS
For 64bit systems, you can install the MongoDB database software package through apt-get. But we need to install the official MongoDB software source.
Modify the source.list file of apt and add the setting of 10gen.
# Download key file
~ sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv 7F0CEB10
Executing: gpg –ignore-time-conflict –no-options –no-default-keyring –secret-keyring /tmp/tmp.kVFab9XYw0 –trustdb-name /etc/apt/trustdb.gpg –keyring / etc/apt/trusted.gpg –primary-keyring /etc/apt/trusted.gpg –keyserver hkp://keyserver.ubuntu.com:80 –recv 7F0CEB10
gpg: Download key ‘7F0CEB10’ from hkp server keyserver.ubuntu.com
gpg: key 7F0CEB10: public key “Richard Kreuter ” imported
gpg: did not find any absolutely trusted keys
gpg: Total number processed: 1
gpg: Imported: 1 (RSA: 1)
# Add MongoDB source configuration in source.list
~ echo ‘deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen’ | sudo tee /etc/apt/sources.list.d/mongodb.list
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
# Update software sources
~ sudo apt-get update
Install MongoDB database in Linux Ubuntu
#Install MongoDB server
~ sudo apt-get install mongodb-10gen
After the installation is complete, the MongoDB server will start automatically, we check the MongoDB server program
# Check MongoDB server system process
~ ps -aux|grep mongo
mongodb 6870 3.7 0.4 349208 39740 ? Ssl 10:27 2:23 /usr/bin/mongod –config /etc/mongodb.conf
# Check the MongoDB server status by starting the command
~ netstat -nlt|grep 27017
tcp 0 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN
# Check the MongoDB server status by starting the command
~ sudo /etc/init.d/mongodb status
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongodb status
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the status(8) utility, e.g. status mongodb
mongodb start/running, process 6870
# Check MongoDB server status through system service
~ sudo service mongodb status
mongodb start/running, process 6870
View the status of the MongoDB server through the web console. Enter http://ip:28017 in the browser
, you can open the console through the web.
3. Access MongoDB through the command line client
Installing the MongoDB server will automatically install the MongoDB command-line client program together.
Enter the mongo command on the local machine to start, and the client program accesses the MongoDB server.
~ mongo
MongoDB shell version: 2.4.9
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type “help”.
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
# View command line help
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
sh.help() sharding helpers
rs.help() replica set helpers
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries with time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memory, ‘global’ is default
use set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit exit the mongo shell
result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit exit the mongo shell