MongoDB資料庫基礎學習!

2021-10-03 16:07:34 字數 2220 閱讀 4572

collection就相對於mysql中的table(表)

use db 使用db資料庫

db.collection.insert()

使用了不存在的物件,即建立該物件。

show dbs 檢視當前伺服器中寫在磁碟上的資料庫

show tables 檢視資料庫中的collection

db 檢視當前使用的資料庫

db.collectiong.inser() 自動生成 _id : objectid("")
官方推薦

db.collection.insetone() 插入一條資料

db.conllection.insetmany(,) 插入多條資料

db.collection.find()

db.collection.finone()

db.collection.updata(,})
官方推薦

db.collection.updataone(,})  更新(第一條)資料

db.collection.updataone(,} 更新所有資料

db.collection.remove()
官方推薦

db.collection.deleteone() 刪除一條資料

db.collection.deletemany() 刪除所有符合條件的資料

db.collection.drop()
數學比較符
數學比較符:

$lt 小於

$lte 小於等於

$gt 大於

$gte 大於等於

$eq : 等於

$eq 等於

查詢關鍵字:

$or db.collection.find(,]}) #會把符合條件的都找出來

$in db.collection.find(}) #在同乙個字段裡面查詢 ,符合其中乙個條件即可

$all db.collection.find(}) #子集查詢

$set 簡單粗暴 } dict["name"]=value 

$unset 簡單粗暴的刪除字段 } del dict["name"]

array操作

db.user_info.updateone(,})

$pull 在array中刪除乙個的元素 .remove(item) .pop(-1)

db.user_info.updateone(,}) #這個0是乙個值,不是索引

$pop 不含索引 -1 從前往後 1 從後往前

db.user_info.updateone(,})

$inc 引用增加 (想一想過生日)

db.user_info.updatemany({},})

db.user_info.updateone(,})

儲存符合索引條件資料的下標 (裡面等於6的)

1.object 字典操作

db.user_info.updateone(,})

db.user_info.updateone(,})

2.array + object

db.user_info.updateone(,})

3.limit

db.user_info.find({}).limit(5)

選取資料從當前位置選擇5個

4.skip 跳過

db.user_info.find({}).skip(2)

從0開始跳過2條資料為當前位置

5.sort

db.user_info.find({}).sort()

根據id進行排序 -1倒敘 1正序

6.limit+skip+sort

db.user_info.find({}).limit(5).skip(10)

db.user_info.find({}).limit(c).skip((p-1)*c)

db.user_info.find({}).limit(5).skip(5).sort()

7.總結

優先順序最高的是 sort

其次優先為 skip

最低優先順序 limit

MongoDB 資料庫基礎

mongodb 資料庫是非關係型資料庫,沒有庫和表,有json物件 mongo.exe 使用資料庫 mongod.exe 開機 mongoimport 匯入資料 操作 將 mongodb 配置成環境變數,方便在cmd命令中執行 1 先開機 mongod dbpath d mongo d mongo是...

MongoDB資料庫基礎入門操作

建立資料庫用於儲存爬蟲資料,節省電腦空間 python對資料庫的基本的操作 鏈結資料前 1 必須確保已經正確安裝了資料庫 2 必須開啟資料庫 import pymongo 連線資料庫 client pymongo.mongoclient host localhost port 27017 指定鏈結資...

mongoDB資料庫 學習筆記(一)

mongodb與傳統數劇庫的不同 文件document vs record 集合 collection vs table 資料庫database vs database server vs server 框架 物件 fastjson json格式 mongodb的學習資料 runoob.com 或者...