MongoDB Learning Note One installation and basic commands

Source: Internet
Author: User

First, MongoDB installation configuration 1, get the latest version:
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.2.tgz
2, decompression can be performed
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但是在运行前,需要创建mongodb需要的存放数据和日志的目录:sudo mkdir -p /data/db/journalsudo chmod -R 777 /data/db/启动mongodb server,-journal 代表要写日志,-maxConns=2400代表mongodb 可以接受2400个   tcp连接,-rest代表可以允许客户端通过rest API访问mongdb server../mongod -journal -maxConns=2400 -rest
3. Related instructions
After the service program starts, the terminal displays some information, such as: Wed 16:40:03 [Initandlisten] MongoDB starting:pid=2410 port=27017 Dbpath=/data/db/64-bitwe D 16:40:03 [Initandlisten] db version v2.0.2, pdfile version 4.5Wed 16:40:03 [Initandlisten] git version:c2 06d77e94bc3b65c76681df5a6b605f68a2de05wed 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 17:48:28 EST x86_64 boost_lib_version=1_41wed 16:40:03 [Initandli Sten] Journal dir=/data/db/journalwed 16:40:03 [Initandlisten] recover:no journal files present, no recovery need Edwed 16:40:06 [Initandlisten] preallocateisfaster=true 33.84Wed 16:40:08 [Initandlisten] Preallocateisfast Er=true 36.84Wed 16:40:11 [Initandlisten] preallocateisfaster=true 37.48Wed 16:40:11 [Initandlisten] Preallo Cating a journal file/data/db/journal/prealloc.0wed 16:41:03 [Initandlisten] preallocating a journal file/data/db /journal/prealloc.1wed 31 16: 41:55 [Initandlisten] preallocating a journal file/data/db/journal/prealloc.2wed-16:42:48 [Initandlisten] Waitin G for connections in Port 27017Wed 16:42:48 [Initandlisten]-maxconns too high, can only handle 819Wed 31 16:42 : [WEBSVR] Web admin interface listening on port 28017
4. Environmental information
机器IP: 10.0.14.218安装目录 : /usr/local/mongodb/bin数据存储目录: /data/dbweb console : http://10.0.14.218:28017/web admin port : 28017
Ii. MongoDB Entry-based command
    • Show DBS: Display Database list
    • Show Collections: Displays a collection in the current database (similar to a table in a relational database)
    • Show Users: Show user
    • Db.help (): Show database Operations Command with a lot of commands
    • Db.foo.find (): Data lookup for the Foo collection in the current database (all data is listed because there are no conditions)
    • Use Yourdb; Toggles the creation of the database, which automatically creates the current database when a collection (table) is created.
    • Db.dropdatabase (); Please use caution when deleting the current database.
    • Db.clonedatabase ("127.0.0.1"); Clones data from a database on a specified machine to the current database
    • Db.copydatabase ("MyDB", "temp", "127.0.0.1"), copy the native mydb data to the TEMP database
    • Db.repairdatabase (); Repairing the current database
    • Db.getname (); Gets the current database name, the same as the DB command effect.
    • Db.stats (); View the status of the DB.
    • Db.version (); View the current version of the DB.
    • Db.getmondo (); View the current MongoDB link server address.
    • Db.createcollection ("Collname", {size:20, Capped:5, max:100}); Creates a clustered collection.

    • Db.getcollection (' dict '); Gets the clustered collection of the specified name.

    • Db.getcollectionnames (); Gets the names of all the clustered collections under the current DB.
    • Db.printcollectionstats (); Displays the status of all clustered indexes in the current DB.
    • Db.dict.help (); View Help
    • Db.adduser ("Zhuoxuan", "admin", true); Add user, set password, read-only
    • Db.auth (' Zhuoxuan ', ' admin '); Database authentication, security mode
    • Show Users; All users are displayed.
    • Db.removeuser ("Zhuoxuan"); Delete 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.