MongoDB基础--数据库和集合基本操作
生活随笔
收集整理的這篇文章主要介紹了
MongoDB基础--数据库和集合基本操作
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
? ??本筆記針對https://www.shiyanlou.com/courses/running/50?網(wǎng)站對mongoDB的學(xué)習(xí)和總結(jié)。 1,啟動mongoDB ? ? 因為mongoDB服務(wù)并不隨著系統(tǒng)一起啟動,所以需要首先啟動mongoDB服務(wù): shiyanlou:~/ $ sudo service mongodb start 2,數(shù)據(jù)庫簡介 shiyanlou:~/ $ mongo
> show dbs
local0.078125GB -1,文檔 ? ? 文檔是mongoDB的核心,類似于關(guān)系型數(shù)據(jù)庫的一行數(shù)據(jù)。多個鍵以及其關(guān)聯(lián)的值放到一起就是文檔。在mongoDB中使用一種類似JSON格式的bson存儲數(shù)據(jù)。bson可以再json基礎(chǔ)上添加一些json不具備的數(shù)據(jù)類型。如: {"company":"Chenshi keji"} -2,文檔邏輯關(guān)系: 嵌入關(guān)系:A文檔中存在B文檔。 ? ? 引用式關(guān)系:兩個文檔分卡,A文檔通過引用B文檔的ID來實現(xiàn)關(guān)聯(lián)。 -3,集合 ? ? 集合就是一組文檔的組合,相當(dāng)于關(guān)系數(shù)據(jù)庫中的表。 {"company":"Chenshi keji"}{"people":"man","name":"peter"} -4,元數(shù)據(jù) ? ? 數(shù)據(jù)庫信息存儲在集合中,他們統(tǒng)一使用系統(tǒng)的命名空間 ? ? DBNAME.system.* DBNAME可以用db或數(shù)據(jù)庫名代替。 DBNAME.system.namespaces :列出所有名字空間
DBNAME.system.indexs :列出所有索引
DBNAME.system.profile :列出數(shù)據(jù)庫概要信息
DBNAME.system.users :列出訪問數(shù)據(jù)庫的用戶
DBNAME.system.sources :列出服務(wù)器信息 2,數(shù)據(jù)庫的創(chuàng)建和銷毀 ? ? -1,創(chuàng)建數(shù)據(jù)庫 使用use命令床架數(shù)據(jù)庫 use mydb 查看當(dāng)前連接的數(shù)據(jù)庫 db 查看所有的數(shù)據(jù)庫 show dbs 列出的數(shù)據(jù)庫中不顯示mydb,是因為mydb為空。 ? ? -2,銷毀數(shù)據(jù)庫。 > db.dropDatabase()
{"dropped":"local","ok":1} 3,集合的創(chuàng)建和銷毀。 ? ? -1,創(chuàng)建集合 > use mydb
switched to db mydb
> db.createCollection("users")
{"ok":1}
> ? ? 查看集合 > show collections
system.indexes
users
> ? ? -2,刪除集合 > db.users.drop()
true
> 4,向集合中插入數(shù)據(jù) ? ? insert 插入數(shù)據(jù)時,如果users集合沒有創(chuàng)建會自動創(chuàng)建。 > db.users.insert([{name:'jam',email:'jam@qq.com'},{name:'tom', email:'tom@q
q.email'}]) ? ? save??插入數(shù)據(jù)時,如果users集合沒有創(chuàng)建會自動創(chuàng)建。 > db.users.save([{name:'jam',email:'jam@qq.com'},{name:'tom', email:'tom@q
q.email'}]) 來自為知筆記(Wiz)
?
- ? ? 一個MongoDB可以創(chuàng)建多個數(shù)據(jù)庫。
- ? ? 使用 show dbs可以查看所有數(shù)據(jù)庫的列表
- ? ? 執(zhí)行db命令則可以查看當(dāng)前數(shù)據(jù)庫對象或者集合。
- ? ? 運行use命令則可以連接到指定的數(shù)據(jù)庫
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/jingLongJun/p/4504635.html
總結(jié)
以上是生活随笔為你收集整理的MongoDB基础--数据库和集合基本操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TreeList右键菜单功能
- 下一篇: fastweixin v1.3.0 发布