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
Ii. Basic commands for getting started with mongodb
- Show dbs: displays the Database List
- Show collections: displays a set in the current database (similar to a table in a relational database)
- Show users: displays users
- Db. help (): displays database operation commands, which contain many commands.
- Db. foo. find (): searches for the foo set in the current database (all data is listed due to no conditions)
- Use yourDB; Switch to create a database. When you create 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
- Db. copyDatabase ("mydb", "temp", "127.0.0.1"); copy the data of mydb on the local machine to the temp database.
- Db. repairDatabase (); fix the current database
- Db. getName (); obtain 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 user, set password, read-only
- Db. auth ('zhuoxuany', 'admin'); database authentication, Security Mode
- Show users; show all users.
- Db. removeUser ("zhuoxuan"); Delete the user account