MongoDB Quick Start
来自Jack's Lab
(版本间的差异)
(→Mongo Shell) |
(→Mongo Shell) |
||
第60行: | 第60行: | ||
connecting to: test | connecting to: test | ||
type "help" for help | type "help" for help | ||
+ | > | ||
+ | > help | ||
+ | HELP | ||
+ | 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 | ||
+ | use <db name> set curent database to <db name> | ||
+ | db.help() help on DB methods | ||
+ | db.foo.help() help on collection methods | ||
+ | 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 | ||
+ | > show dbs | ||
+ | admin | ||
+ | local | ||
+ | > use test | ||
+ | switched to db test | ||
> | > | ||
</source> | </source> |
2014年12月16日 (二) 13:57的版本
1 Install
comcat@maike:~# apt-get install mongodb Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: libboost-filesystem1.42.0 libboost-program-options1.42.0 libboost-system1.42.0 libboost-thread1.42.0 libmozjs2d libpcrecpp0 mongodb-clients mongodb-dev mongodb-server ...... ...... Processing triggers for man-db ... Setting up libboost-system1.42.0 (1.42.0-4) ... Setting up libboost-filesystem1.42.0 (1.42.0-4) ... Setting up libboost-program-options1.42.0 (1.42.0-4) ... Setting up libboost-thread1.42.0 (1.42.0-4) ... Setting up libmozjs2d (1.9.1.16-20) ... Setting up libpcrecpp0 (8.02-1.1) ... Setting up mongodb-clients (1:1.4.4-3) ... Setting up mongodb-server (1:1.4.4-3) ... Adding system user `mongodb' (UID 105) ... Adding new user `mongodb' (UID 105) with group `nogroup' ... Not creating home directory `/home/mongodb'. Adding group `mongodb' (GID 110) ... Done. Adding user mongodb to group mongodb Done. Starting database: mongodb. Setting up mongodb-dev (1:1.4.4-3) ... Setting up mongodb (1:1.4.4-3) ... comcat@maike:~# ps ax|grep mongo 30109 ? Sl 0:00 /usr/bin/mongod --dbpath /var/lib/mongodb --logpath /var/log/mongodb/mongodb.log --config /etc/mongodb.conf run 30319 pts/0 S+ 0:00 grep mongo
The configuration file is located at /etc/mongodb.conf
It use /var/lib/mongodb as the database directory by default. You can modify it as you like.
2 Mongo Shell
comcat@maike:~# dpkg -L mongodb-clients | grep bin /usr/bin /usr/bin/mongo /usr/bin/mongodump /usr/bin/mongoexport /usr/bin/mongofiles /usr/bin/mongoimport /usr/bin/mongorestore /usr/bin/mongostat comcat@maike:~# mongo MongoDB shell version: 1.4.4 url: test connecting to: test type "help" for help > > help HELP 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 use <db name> set curent database to <db name> db.help() help on DB methods db.foo.help() help on collection methods 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 > show dbs admin local > use test switched to db test >