MongoDB: Instalando o MongoDB no Linux

From Wiki
Revision as of 22:50, 31 December 2015 by Ebasso (talk | contribs) (→‎Ver também)

Instalando o MongoDB

Vamos instalar o MongoDB

1. Abra um terminal

2. Instale o MongoDB

Fedora.
$ sudo dnf -y install mongodb.x86_64 mongodb-server.x86_64 nodejs-mongodb.noarch
Red Hat® Enterprise Linux® / RHEL, CentOS
$ sudo yum -y install mongodb.x86_64 mongodb-server.x86_64 nodejs-mongodb.noarch

3. Configurar


Executando o servidor MongoDB

Iniciando:

systemctl start mongod

Verificando a execução:

systemctl status mongod

Verificando o servidor

# mongostat 

Resultado:

connected to: 127.0.0.1
insert  query update delete getmore command flushes mapped  vsize    res faults  locked db idx miss %     qr|qw   ar|aw  netIn netOut  conn       time 
   *0     *0     *0     *0       0     1|0       0    80m   436m    39m      0 local:0.0%          0       0|0     0|0    62b     3k     1   20:03:55 
   *0     *0     *0     *0       0     1|0       0    80m   436m    39m      0 local:0.0%          0       0|0     0|0    62b     3k     1   20:03:56 
   *0     *0     *0     *0       0     1|0       0    80m   436m    39m      0 local:0.0%          0       0|0     0|0    62b     3k     1   20:03:57 
   *0     *0     *0     *0       0     1|0       0    80m   436m    39m      0 local:0.0%          0       0|0     0|0    62b     3k     1   20:03:58 
...
Ctrl-c para parar.

Conectando via Cliente

$ mongo

MongoDB shell version: 2.6.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

Ajuda:

> 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 <db_name>                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

Saindo

> exit

Executando o servidor MongoDB

Parando:

systemctl stop mongod

Ver também