您好,登錄后才能下訂單哦!
1)Mongodb屬于非關(guān)系性數(shù)據(jù)庫 ,數(shù)據(jù)記錄以文檔形式(鍵值對)進行存儲,即bson格式
2)不再有“行”(row)的概念,其運行方式主要基于兩個概念:集合(collection)與文檔(document)
3)支持各種編程語言:Ruby,Python,Java,C++,PHP,C#等多種語言
關(guān)系型:數(shù)據(jù)庫------》表------------》記錄,字段
非關(guān)系型:數(shù)據(jù)庫-----------》集合----------》鍵值對
書寫格式:{鍵值:值}
鍵值對:如{“name”:”zhangsan”} 鍵值必須雙引號,值如果是數(shù)值(int)可以不用雙引號引起來,如果是字符串(string)必須用雙引號引起來。
vim /etc/yum.repos.d/mongodb.repo
[mongodb-org]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/ #指定獲得下載的路徑
gpgcheck=1 #表示對從這個源下載的rpm包進行校驗
enabled=1 #表示啟用這個源。
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
yum list
yum -y install mongodb-org
vim /etc/mongod.conf
..........
bindIp:0.0.0.0 #監(jiān)聽任意地址
port:27017 #默認監(jiān)聽端口
mongodb服務(wù)的啟動,關(guān)閉有兩種方式
(1)systemctl start mongod.service #啟動
systemctl stop mongod.service #關(guān)閉
(2) mongod -f /etc/mongod.conf #啟動
mongod -f /etc/mongod.conf --shutdown #關(guān)閉
netstat -antp | grep mongod
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 16540/mongod
不需要使用密碼直接使用mongo命令進入服務(wù)
> db.version()
3.6.7
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
myschool 0.000GB
school 0.000GB
> use yun
switched to db yun
> db.createCollection("abc")
{ "ok" : 1 }
> db.info.insert({"id":1,"name":"jack1"})
WriteResult({ "nInserted" : 1 })
> show tables
info
> show collections
info
> for (var i=2;i<=100;i++)db.abc.insert({"id":i,"name":"jack"+i});
WriteResult({ "nInserted" : 1 })
> db.abc.find()
db.abc.findOne({"id":10})
{
"_id" : ObjectId("5b972d38fb89e57a63998a84"),
"id" : 10,
"name" : "jack10"
> a=db.abc.findOne({"id":10}) #把這條記錄定義別名為a
{
"_id" : ObjectId("5b9a6f39e80a2611eecb6f7b"),
"id" : 10,
"name" : "jack10"
> typeof(a.id)
number
> typeof(a.name)
String
db.info.update({"id":10},{$set:{"name":"tom10"}}) 格式:條件在前,修改在后
db.info.findOne({"id":10})
{
"_id" : ObjectId("5b972d38fb89e57a63998a84"),
"id" : 10,
"name" : "tom10"
db.info.count()
100
db.info.remove({"id":12}) //刪除數(shù)據(jù)
Db.info.drop() //刪除集合
先進入該數(shù)據(jù)庫,再用下面的命令刪除數(shù)據(jù)庫
Use school
db.dropDatebase() //刪除數(shù)據(jù)庫
db.runCommand({"clonecollection":"school.info","from":"192.168.195.137:27017"})
mongoexport -d school -c info -o /opt/school.jason
mongoexport -d school -c info -q '{"id":{"$eq":10}}' -o /opt/school10.jason
mongoimport -d school -c infos --file /opt/school.jason
mongodump -d yunwei(庫名) -o /opt(路徑)
mongorestore -d yunjisuan2 --dir=/opt/yunjisuan
在mongodb中進行授權(quán)
> use admin
switched to db admin
> db.createUser({"user":"root","pwd":"abc123","roles":["root"]})
Successfully added user: { "user" : "root", "roles" : [ "root" ] }
vim /etc/mongod.conf
auth=true
vim mongodb.conf
> use admin
switched to db admin
> db.auth("root","abc123")
1
> show dbs
admin 0.078GB
local 0.078GB
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。