MongoDB 安装(Mac)

版权声明:欢迎转载,转载请说明出处. 大数据Github项目地址https://github.com/SeanYanxml/bigdata。 https://blog.csdn.net/u010416101/article/details/90146126

前言

  • MongoDB安装
  • GUI工具

  • 下载MongoDB安装包
localhost:MongoDB Sean$ sudo curl -O https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.4.2.tgz
Password:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 78.2M  100 78.2M    0     0   107k      0  0:12:28  0:12:28 --:--:--  132k
  • 设置安装地址
localhost:MongoDB Sean$ tar -zxvf mongodb-osx-x86_64-3.4.2.tgz
x mongodb-osx-x86_64-3.4.2/README
x mongodb-osx-x86_64-3.4.2/THIRD-PARTY-NOTICES
x mongodb-osx-x86_64-3.4.2/MPL-2
x mongodb-osx-x86_64-3.4.2/GNU-AGPL-3.0
x mongodb-osx-x86_64-3.4.2/bin/mongodump
x mongodb-osx-x86_64-3.4.2/bin/mongorestore
x mongodb-osx-x86_64-3.4.2/bin/mongoexport
x mongodb-osx-x86_64-3.4.2/bin/mongoimport
x mongodb-osx-x86_64-3.4.2/bin/mongostat
x mongodb-osx-x86_64-3.4.2/bin/mongotop
x mongodb-osx-x86_64-3.4.2/bin/bsondump
x mongodb-osx-x86_64-3.4.2/bin/mongofiles
x mongodb-osx-x86_64-3.4.2/bin/mongooplog
x mongodb-osx-x86_64-3.4.2/bin/mongoreplay
x mongodb-osx-x86_64-3.4.2/bin/mongoperf
x mongodb-osx-x86_64-3.4.2/bin/mongod
x mongodb-osx-x86_64-3.4.2/bin/mongos
x mongodb-osx-x86_64-3.4.2/bin/mongo

localhost:MongoDB Sean$ ln -s /Users/Sean/Software/MongoDB/mongodb-osx-x86_64-3.4.2 current

localhost:MongoDB Sean$ ls -lrt
total 240776
-rw-r--r--@ 1 Sean  staff  39326176 Apr 18  2018 nosqlbooster4mongo-4.5.2.exe
drwxr-xr-x  3 Sean  staff        96 May  3 17:16 data
-rw-r--r--  1 root  staff  82068786 May  3 17:34 mongodb-osx-x86_64-3.4.2.tgz
drwxr-xr-x  7 Sean  staff       224 May  3 17:34 mongodb-osx-x86_64-3.4.2
lrwxr-xr-x  1 Sean  staff        53 May  3 17:35 current -> /Users/Sean/Software/MongoDB/mongodb-osx-x86_64-3.4.2
  • 设置环境变量/etc/profile
export MONGODB_HOME=/Users/Sean/Software/MongoDB/current
export PATH=$PATH:$MONGODB_HOME/bin

随后source /etc/profile使其立即生效.

mongo -v 查看其是否生效
  • 启动MongoDB Server端
localhost:MongoDB Sean$ mongod --dbpath=/Users/Sean/Software/MongoDB/data/db
2019-05-10T17:09:07.387+0800 I CONTROL  [initandlisten] MongoDB starting : pid=50188 port=27017 dbpath=/Users/Sean/Software/MongoDB/data/db 64-bit host=localhost
2019-05-10T17:09:07.388+0800 I CONTROL  [initandlisten] db version v3.4.2
2019-05-10T17:09:07.388+0800 I CONTROL  [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2019-05-10T17:09:07.388+0800 I CONTROL  [initandlisten] allocator: system
2019-05-10T17:09:07.388+0800 I CONTROL  [initandlisten] modules: none
2019-05-10T17:09:07.388+0800 I CONTROL  [initandlisten] build environment:
2019-05-10T17:09:07.388+0800 I CONTROL  [initandlisten]     distarch: x86_64
2019-05-10T17:09:07.388+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2019-05-10T17:09:07.388+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "/Users/Sean/Software/MongoDB/data/db" } }
2019-05-10T17:09:07.391+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2019-05-10T17:09:07.681+0800 I CONTROL  [initandlisten]
2019-05-10T17:09:07.681+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-05-10T17:09:07.681+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-05-10T17:09:07.681+0800 I CONTROL  [initandlisten]
2019-05-10T17:09:07.739+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/Users/Sean/Software/MongoDB/data/db/diagnostic.data'
2019-05-10T17:09:07.833+0800 I INDEX    [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2019-05-10T17:09:07.833+0800 I INDEX    [initandlisten] 	 building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2019-05-10T17:09:07.845+0800 I INDEX    [initandlisten] build index done.  scanned 0 total records. 0 secs
2019-05-10T17:09:07.846+0800 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 3.4
2019-05-10T17:09:07.847+0800 I NETWORK  [thread1] waiting for connections on port 27017
2019-05-10T17:10:14.676+0800 I NETWORK  [thread1] connection accepted from 127.0.0.1:59809 #1 (1 connection now open)
2019-05-10T17:10:14.678+0800 I NETWORK  [conn1] received client metadata from 127.0.0.1:59809 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.2" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "18.0.0" } }
2019-05-10T17:11:31.531+0800 I NETWORK  [thread1] connection accepted from 127.0.0.1:59831 #2 (2 connections now open)
2019-05-10T17:11:31.532+0800 I NETWORK  [conn2] received client metadata from 127.0.0.1:59831 conn2: { application: { name: "robo3t" }, driver: { name: "MongoDB Internal Client", version: "3.4.3-10-g865d2fb" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "18.0.0" } }
2019-05-10T17:11:31.585+0800 I NETWORK  [thread1] connection accepted from 127.0.0.1:59832 #3 (3 connections now open)
2019-05-10T17:11:31.585+0800 I NETWORK  [conn3] received client metadata from 127.0.0.1:59832 conn3: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.3-10-g865d2fb" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "18.0.0" } }
2019-05-10T17:11:34.343+0800 I -        [conn2] end connection 127.0.0.1:59831 (3 connections now open)
2019-05-10T17:11:34.344+0800 I -        [conn3] end connection 127.0.0.1:59832 (2 connections now open)
2019-05-10T17:11:36.937+0800 I NETWORK  [thread1] connection accepted from 127.0.0.1:59834 #4 (2 connections now open)
2019-05-10T17:11:36.937+0800 I NETWORK  [conn4] received client metadata from 127.0.0.1:59834 conn4: { application: { name: "robo3t" }, driver: { name: "MongoDB Internal Client", version: "3.4.3-10-g865d2fb" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "18.0.0" } }
2019-05-10T17:11:36.982+0800 I NETWORK  [thread1] connection accepted from 127.0.0.1:59835 #5 (3 connections now open)
2019-05-10T17:11:36.983+0800 I NETWORK  [conn5] received client metadata from 127.0.0.1:59835 conn5: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.3-10-g865d2fb" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "18.0.0" } }
2019-05-10T17:19:44.030+0800 I COMMAND  [conn1] CMD: drop yanxml.yanxml_collection
2019-05-10T17:26:30.028+0800 W COMMAND  [conn1] the autoIndexId option is deprecated and will be removed in a future release
2019-05-10T19:32:51.827+0800 I NETWORK  [thread1] connection accepted from 127.0.0.1:61486 #6 (4 connections now open)
2019-05-10T19:32:51.827+0800 I NETWORK  [conn6] received client metadata from 127.0.0.1:61486 conn6: { application: { name: "robo3t" }, driver: { name: "MongoDB Internal Client", version: "3.4.3-10-g865d2fb" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "18.0.0" } }
2019-05-10T19:32:51.868+0800 I NETWORK  [thread1] connection accepted from 127.0.0.1:61487 #7 (5 connections now open)
2019-05-10T19:32:51.868+0800 I NETWORK  [conn7] received client metadata from 127.0.0.1:61487 conn7: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.3-10-g865d2fb" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "18.0.0" } }
2019-05-10T21:28:58.569+0800 I -        [conn6] end connection 127.0.0.1:61486 (5 connections now open)
2019-05-10T21:28:58.587+0800 I -        [conn7] end connection 127.0.0.1:61487 (4 connections now open)
2019-05-10T21:28:58.656+0800 I -        [conn5] end connection 127.0.0.1:59835 (3 connections now open)
2019-05-10T21:28:58.656+0800 I -        [conn4] end connection 127.0.0.1:59834 (3 connections now open)
2019-05-12T00:29:59.132+0800 I COMMAND  [PeriodicTaskRunner] task: DBConnectionPool-cleaner took: 111ms

  • 启动MongoDB Client端
localhost:~ Sean$ mongo
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2
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
Server has startup warnings:
2019-05-10T17:09:07.681+0800 I CONTROL  [initandlisten]
2019-05-10T17:09:07.681+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-05-10T17:09:07.681+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-05-10T17:09:07.681+0800 I CONTROL  [initandlisten]
> 1+1
2
> show dbs
admin  0.000GB
local  0.000GB
> db
test
> use local
switched to db local
> db
local
> var newObject = ObjectId()
> newObject.getTimestamp()
ISODate("2019-05-10T09:16:13Z")
> newObject.str
5cd5415de6b987425bc13717
> use yanxml
switched to db yanxml
> db
yanxml
> show dbs
admin  0.000GB
local  0.000GB
> db
yanxml
> show dbs
admin  0.000GB
local  0.000GB
> db.yanxml.insert({"name":"www.yanxml.com"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin   0.000GB
local   0.000GB
yanxml  0.000GB
> show tables
yanxml
> db.createCollection("yanxml_collection")
{ "ok" : 1 }
> show tables
yanxml
yanxml_collection
> db.yanxml_collection.drop()
true
> show tables
yanxml
> show db.createCollection("mycol", { capped : true, autoIndexId : true, size :
...    6142800, max : 10000 } )
2019-05-10T17:26:09.266+0800 E QUERY    [thread1] SyntaxError: missing ) after argument list @(shellhelp2):1:45
> show tables
yanxml
> db.createCollection("mycol", { capped : true, autoIndexId : true, size :
...    6142800, max : 10000 } )
{
	"note" : "the autoIndexId option is deprecated and will be removed in a future release",
	"ok" : 1
}
> show tables
mycol
yanxml
  • GUI 工具Robo 3T链接
    在这里插入图片描述
    在这里插入图片描述

Reference

[1]. Runoob - MongoDB

展开阅读全文

没有更多推荐了,返回首页