MongoDB 是一個基於分佈式文件存儲的數據庫。由 C++ 語言編寫。旨在爲 WEB 應用提供可擴展的高性能數據存儲解決方案。linux
MongoDB 是一個介於關係型數據庫和非關係型數據庫之間的產品,是非關係數據庫當中功能最豐富,最像關係型的數據庫。mongodb
MongoDB 將數據存儲爲一個文檔,數據結構由鍵值(key=>value)對組成。MongoDB 文檔相似於 JSON 對象。字段值能夠包含其餘文檔,數組及文檔數組。數據庫
yum install libcurl openssl
下載地址: https://www.mongodb.com/download-center?jmp=nav#community
mkdir -p /app/mongodb4.0/{install,logs,conf,data}
tar xf mongodb-linux-x86_64-4.0.0.tgz -C /app/mongodb4.0/install/
touch /app/mongodb4.0/logs/mongodb.log touch /app/mongodb4.0/conf/mongodb.conf
port=27017 fork=true logpath=/app/mongodb4.0/logs/mongodb.log #logappen=true dbpath=/app/mongodb4.0/data auth=false
/app/mongodb4.0/install/bin/mongod -f /app/mongodb4.0/conf/mongodb.conf
/app/mongodb4.0/install/bin/mongo 127.0.0.1:27017
use demon
在admin數據庫中添加具備userAdminAnyDatabase角色的用戶編程
use admin
db.createUser({user:"admin",pwd:"admin",roles:[{role:"readWrite",db:"demon"}]});
db.createUser({user:"admin",pwd:"admin",roles:[{role:"readWriteAnyDatabase",db:"demon"}]});
/app/mongodb4.0/install/bin/mongod -f /app/mongodb4.0/conf/mongodb.conf -shutdown
/app/mongodb4.0/install/bin/mongod -f /app/mongodb4.0/conf/mongodb.conf
/app/mongodb4.0/install/bin/mongo --port 27017 -u "admin" -p "admin" --authenticationDatabase "admin"
#!/bin/bash # chkconfig: - 98 21 Mongod_Path="/app/mongodb4.0/install/bin/mongod" Mongod_Conf="/app/mongodb4.0/conf/mongodb.conf" usage() { echo "usage: $0 [start|stop|restart]" } start_Mongod() { $Mongod_Path -f $Mongod_Conf echo "Mongodb is starting" } stop_Mongod() { $Mongod_Path -f $Mongod_Conf --shutdown echo "Mongodb is stopped" } main() { case $1 in start) start_Mongod;; stop) stop_Mongod;; restart) stop_Mongod && start_Mongod;; *) usage; esac } main $1
chmod +x /etc/init.d/mongod
chkconfig --add mongod
/etc/init.d/mongod start /etc/init.d/mongod stop /etc/init.d/mongod restart
> show dbs; #查看當前實例下的數據庫
> show databases; #兼容關係型數據庫MySQL命令
> use local; #切換數據庫local
> show collections; #查看數據庫local的集合
> show tables; #兼容關係型數據庫MySQL命令
經常使用的操做以下:數組