安装步骤参考官方文档 : Install Mongodb
此处使用Brew安装
安装
brew install mongodb
查看帮助文件
promote:~ wallent$ mongo -help
MongoDB shell version v3.4.2
usage: mongo [options] [db address] [file names (ending in .js)]
db address can be:
foo foo database on local machine
192.168.0.5/foo foo database on 192.168.0.5 machine
192.168.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
Options:
--shell run the shell after executing files
--nodb don't connect to mongod on startup - no
'db address' arg expected
--norc will not run the ".mongorc.js" file on
start up
--quiet be less chatty
--port arg port to connect to
--host arg server to connect to
--eval arg evaluate javascript
-h [ --help ] show this usage information
--version show version information
--verbose increase verbosity
--ipv6 enable IPv6 support (disabled by default)
--disableJavaScriptJIT disable the Javascript Just In Time
compiler
--disableJavaScriptProtection allow automatic JavaScript function
marshalling
--ssl use SSL for all connections
--sslCAFile arg Certificate Authority file for SSL
--sslPEMKeyFile arg PEM certificate/key file for SSL
--sslPEMKeyPassword arg password for key in PEM file for SSL
--sslCRLFile arg Certificate Revocation List file for SSL
--sslAllowInvalidHostnames allow connections to servers with
non-matching hostnames
--sslAllowInvalidCertificates allow connections to servers with invalid
certificates
--sslFIPSMode activate FIPS 140-2 mode at startup
--networkMessageCompressors arg Comma-separated list of compressors to
use for network messages
--jsHeapLimitMB arg set the js scope's heap size limit
Authentication Options:
-u [ --username ] arg username for authentication
-p [ --password ] arg password for authentication
--authenticationDatabase arg user source (defaults to dbname)
--authenticationMechanism arg authentication mechanism
--gssapiServiceName arg (=mongodb) Service name to use when authenticating
using GSSAPI/Kerberos
--gssapiHostName arg Remote host name to use for purpose of
GSSAPI/Kerberos authentication
file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified
配置启动
配置:
promote:~ wallent$ cat /usr/local/etc/mongod.conf
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
dbPath:Mongodb存储数据所在文件夹
path:Mongodb的日志记录文件
bindIp:绑定的本机Ip地址
根据需要可对应修改,也可以自己写一个新的conf文件来加载。
启动MongoDB
sudo mongod --config /usr/local/etc/mongod.conf
使用MongoDB
另起一个Bash窗口,输入mongo 就进入Mongodb了
promote:~ wallent$ mongo
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2
Server has startup warnings:
2017-03-13T13:59:30.129+0800 I CONTROL [initandlisten]
2017-03-13T13:59:30.129+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-13T13:59:30.129+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-03-13T13:59:30.129+0800 I CONTROL [initandlisten]
2017-03-13T13:59:30.129+0800 I CONTROL [initandlisten]
2017-03-13T13:59:30.129+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>