MongoDB Study Notes 1 installation and basic commands

Source: Internet
Author: User
Tags mongodb server

1. install and configure MongoDB 1. obtain the latest version:

wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.2.tgz
2. Extract the package and run it.
Tar zxvf mongodb-linux-x86_64-2.0.2.tgztar zxvf mongodb-linux-x86_64-2.0.2.tgzcd/usr/mongodb-linux-x86_64-2.0.2/bin but before running, you need to create a directory where mongodb needs to store data and logs: sudo mkdir-p/data/db/journalsudo chmod-R 777/data/db/start mongodb server,-journal indicates to write logs, -maxConns = 2400 indicates that mongodb can accept 2400 tcp connections.-rest indicates that the client can access the mongdb server through the rest API .. /mongod-journal-maxConns = 2400-rest
3. Description
After the service program is started, the listener will display some information, such as: Wed Aug 31 16:40:03 [initandlisten] MongoDB starting: pid = 2410 port = 27017 dbpath =/data/db/64-bitWed Aug 31 16:40:03 [initandlisten] db version v2.0.2, pdfile version 4.5Wed Aug 31 16:40:03 [initandlisten] git version: c206d77e94bc3b65c76681df5a6b605f68a2de05Wed Aug 31 16:40:03 [initandlisten] build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2. ec2.v1.2. fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION = 41541wed Aug 31 16:40:03 [initandlisten] journal dir =/data/db/journalWed Aug 31 16:40:03 [initandlisten] recover: no journal files present, no recovery neededWed Aug 31 16:40:06 [initandlisten] enabled = true enabled Aug 31 16:40:08 [initandlisten] enabled = true enabled Aug 31 16:40:11 [initandlisten] enabled = true 37.48Wed Aug 31 16:40:11 [initandlisten] preallocating a journal file/data/db/journal/prealloc.0Wed Aug 31 16:41:03 [initandlisten] preallocating a journal file/data/db/journal/logs Aug 31 16:41:55 [initandlisten] preallocating a journal file/ data/db/journal/prealloc.2Wed Aug 31 16:42:48 [initandlisten] waiting for connections on port 27017Wed Aug 31 16:42:48 [initandlisten]-maxConns too high, can only handle 819Wed Aug 31 16:42:48 [websvr] web admin interface listening on port 28017
4. Environment Information
Machine IP Address: 10.0.14.218 installation directory:/usr/local/mongodb/bin data storage directory:/data/dbweb console: http: // 10.0.14.218: 28017/web admin port: 28017
2. Basic commands for getting started with mongodb show dbs: display the Database List show collections: display the set in the current database (similar to the tables in the relational database) show users: display the user db. help (): displays database operation commands. There are many commands in the database. foo. find (): Search for the foo set in the current database (all data is listed due to no conditions) use yourDB; Switch to create a database when creating a set (table) the current database is automatically created. Db. dropDatabase (); Delete the current database with caution. Db. cloneDatabase ("127.0.0.1"); clone the database data on the specified machine to the current database. copyDatabase ("mydb", "temp", "127.0.0.1"); copy the data of mydb on the local machine to the database in the temp database. repairDatabase (); fix the current database. getName (); get the name of the current database, which is the same as the db command. Db. stats (); view the database status. Db. version (); view the current db version. Db. getMondo (); view the link server address of the current mongodb instance.

Db. createCollection ("collName", {size: 20, capped: 5, max: 100}); Create a collection.

Db. getCollection ('dict '); obtains the aggregation set with the specified name.

Db. getCollectionNames (); obtain the names of all clustering sets in the current db. Db. printCollectionStats (); displays the status of all clustered indexes of the current db. Db. dict. help (); view help db. addUser ("zhuoxuan", "admin", true); add a user, set a password, and check whether the database is read-only. auth ('zhuoxuany', 'admin'); database authentication, Security Mode show users; show all users. Db. removeUser ("zhuoxuan"); Delete the user account

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.