MongoDB For Mac

2019-03-05  本文已影响5人  我叫Aliya但是被占用了

来自 https://blog.csdn.net/thatway_wp/article/details/79362261

1. 启动

# 进入 /usr/local
cd /usr/local

# 下载
sudo curl -O https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.3.tgz

# 解压
sudo tar -zxvf mongodb-osx-ssl-x86_64-3.6.3.tgz

# 重命名为 mongodb 目录
sudo mv mongodb-osx-x86_64-3.6.3 mongodb
export PATH=/usr/local/mongodb/bin:$PATH

mongod --version

屏幕快照 2019-01-31 下午4.08.50.png
mongod --dbpath=./mongodata/ --logpath=./mongodata/log/mongodb.log --logappend --fork

// 启动
> mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
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-01-31T16:25:32.582+0800 I CONTROL  [initandlisten] 
2019-01-31T16:25:32.583+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-31T16:25:32.584+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-01-31T16:25:32.584+0800 I CONTROL  [initandlisten] 
2019-01-31T16:25:32.585+0800 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2019-01-31T16:25:32.585+0800 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
2019-01-31T16:25:32.586+0800 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
2019-01-31T16:25:32.587+0800 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2019-01-31T16:25:32.587+0800 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2019-01-31T16:25:32.588+0800 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2019-01-31T16:25:32.589+0800 I CONTROL  [initandlisten] 
2019-01-31T16:25:32.589+0800 I CONTROL  [initandlisten] 
2019-01-31T16:25:32.590+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

2.常见命令

> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
> use piaopiao    -- 创建
switched to db piaopiao
> db
piaopiao
> db.createCollection('movie')
{ "ok" : 1 }
> show collections
movie
> db.movie.insert({name:'死侍2:我爱我家', ThrD: true, maker: '大卫·雷奇', actor: '瑞安·雷诺兹', point: '8.7', img: 'i3.jpg_300x300.jpg'})
WriteResult({ "nInserted" : 1 })
> db.movie.find({})
{ "_id" : ObjectId("5c52d8034890c01cc51541f5"), "name" : "死侍2:我爱我家", "ThrD" : true, "maker" : "大卫·雷奇", "actor" : "瑞安·雷诺兹", "point" : "8.7", "img" : "i3.jpg_300x300.jpg" }

> db.movie.update({ThrD: true}, {$set: {ThrD: false}}, {multi: true})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.movie.find({})
{ "_id" : ObjectId("5c52d8034890c01cc51541f5"), "name" : "死侍2:我爱我家", "ThrD" : false, "maker" : "大卫·雷奇", "actor" : "瑞安·雷诺兹", "point" : "8.7", "img" : "i3.jpg_300x300.jpg" }

> db.movie.insert({name:'死侍1'})
WriteResult({ "nInserted" : 1 })
> db.movie.find({})
{ "_id" : ObjectId("5c52d8034890c01cc51541f5"), "name" : "死侍2:我爱我家", "ThrD" : false, "maker" : "大卫·雷奇", "actor" : "瑞安·雷诺兹,乔什·布洛林,莫蕾娜·巴卡林,布里安娜·希尔德布兰,莎姬·贝兹", "point" : "8.7", "img" : "https://img.alicdn.com/bao/uploaded/i3/TB1Yz.yBYrpK1RjSZTEXXcWAVXa_.jpg_300x300.jpg" }
{ "_id" : ObjectId("5c52e084dc993f4e56e17686"), "name" : "死侍1" }
> db.movie.remove({name: "死侍1"})
WriteResult({ "nRemoved" : 1 })
> db.movie.find({})
{ "_id" : ObjectId("5c52d8034890c01cc51541f5"), "name" : "死侍2:我爱我家", "ThrD" : false, "maker" : "大卫·雷奇", "actor" : "瑞安·雷诺兹,乔什·布洛林,莫蕾娜·巴卡林,布里安娜·希尔德布兰,莎姬·贝兹", "point" : "8.7", "img" : "https://img.alicdn.com/bao/uploaded/i3/TB1Yz.yBYrpK1RjSZTEXXcWAVXa_.jpg_300x300.jpg" }

-------------------- 2.28更新

 cd /usr/local/mongodb/bin 
 sudo ./mongod --config /users/aliya/documents/mongodata/etc/mongo.conf
sudo ./mongo
上一篇 下一篇

猜你喜欢

热点阅读