mongoDB數(shù)據(jù)庫由以下?部分構(gòu)成
-
數(shù)據(jù)庫(Database)
-
表(collection)
記錄(document)
字段
字段
記錄(document)
記錄(document)
-
表(collection)
記錄(document)
記錄(document)
記錄(document)
-
mongoDB數(shù)據(jù)庫是什么
數(shù)據(jù)庫:數(shù)據(jù)庫是結(jié)構(gòu)化信息的集合。數(shù)據(jù)庫系統(tǒng)包含兩??:1.庫 2.庫的管理系統(tǒng)
Collection(表): 表是?來存儲數(shù)據(jù)蟀给,?個(gè)數(shù)據(jù)庫?可以有多個(gè)表。?個(gè)表就是document的集合。表?存儲的是?
條?條的記錄莉御,這個(gè)記錄被稱為“document”劳秋。
document(記錄): 表示?條數(shù)據(jù)的記錄分尸。在mongodb數(shù)據(jù)庫中,document通常存儲著?個(gè)對象当编。
mongoDB是?種NOSQL?格的數(shù)據(jù)庫。
Not Only SQL 不僅僅是結(jié)構(gòu)化查詢語?徒溪。
SQLServer和mySQL都屬于SQL(結(jié)構(gòu)化查詢語?)?格的數(shù)據(jù)庫忿偷。
BSON: Binary JSON 的簡寫金顿。翻譯:?進(jìn)制存儲的JSON。
數(shù)據(jù)庫的CRUB操作
c: create 增
R: Rding 查
U:Update 改
D:Drop 刪
db.collection.inserOne()
定義
insertOne()
?于向數(shù)據(jù)庫表?添加?條記錄.
語法
db.你的表名.inserOne({})//參數(shù)的語法符合js對象的語法鲤桥。
返回值
返回?個(gè)對象揍拆,該對象有兩個(gè)屬性
{
acknowledge: boolean,//true表示數(shù)據(jù)被認(rèn)可
insertedIds:ObjectId('字符串id') //由系統(tǒng)?動分配的該記錄的id
}
db.collection.inserMany()
定義
`insertMany()` ?于向數(shù)據(jù)庫表?添加?組記錄。
語法
db.你的表名.inserMany([{document},{document}])//參數(shù)的語法符合js對象的語法芜壁。
返回值
返回?個(gè)對象礁凡,該對象有兩個(gè)屬性
{
acknowledge: boolean,//true表示數(shù)據(jù)被認(rèn)可
insertedIds:ObjectId('字符串id') //由系統(tǒng)?動分配的該記錄的id
}
db.collection.find()
定義
find()
?于檢索/查詢數(shù)據(jù)庫表?的記錄。
語法
db.你的表名.find() //?參數(shù)慧妄,表示檢索表中的全部記錄顷牌。默認(rèn)每次最多20條記錄
# 查看下?組20條數(shù)據(jù)
it//只需輸?it,回?就可以翻?了塞淹。(it:iterate 迭代)
db.你的表名.find({queryObject})//queryObject:查詢條件對象 按條件檢索
返回值
返回檢索到的數(shù)據(jù)記錄窟蓝。
示例
db.collection.find({_id:"640fd6f30b4e5421288fbef0"})
db.collection.find({author:"張三"})
?法
insertOne()
insertMany()
Find() 查詢所有
Find({字段}) 單條件查詢
find({字段1,字段2}) 多條件查詢
-
find({條件查詢對象},{限制查詢})
- find({},{title:1,content:1})
findOne({條件查詢對象}) 返回匹配到的第?條記錄
db.表名.deleteMany({})
db.表名.deleteOne()
db.表名.find().count()
db.表名.find().limit(3)
字段
字段就是 字段名: 字段值
{
字段名1: 字段值1,
字段名2: 字段值2,
title: '標(biāo)題'
}
db.queryObject()
定義:
find()用于
下午
db.collection.find().sort({字段名: -1})
1 : 表示升序排列
-1: 表示降序排列
操作符
mongoDB中提供了許多操作符,操作符的標(biāo)志:$開頭,
操作符是字段名饱普。
語法格式:
$操作符:{}
- $gt:大于過濾器 great than 大于
- $lt:小于 less than 小于
- $gte:大于等于 great than equal 1 + 1 = 2 on plus one equal 2
- $lte:小于等于 less than equal
- $or:或
- $and :并且
- $in:查詢
- $nin:不查詢
- $set:設(shè)置
$gt語法
db.posts.find({字段名: {$gt:字段值}})
$lt語法
db.posts.find({字段名: {$lt:字段值}})
$gte語法
db.posts.find({字段名: {$get:字段值}})
$lte語法
db.posts.find({字段名: {$lte:字段值}})
$or語法
db.posts.find({$or:[{author:"小王"},{author:"小米"}]})
$and語法
db.posts.find({$and:[{author:"小王"},{like:100}]})
$in語法
db.posts.find({link:{$in: [100,488,788]}})
$nin語法
db.posts.find({link:{$nin: [100,488,788]}})
db.posts.updateOne({更新那個(gè)},{更新內(nèi)容})
定義:用于更新一條數(shù)據(jù)
db.posts.updateOne({id: ObjectId("640fe6cbed6961c9515fc875")},{$set:{author:"大米",link:200}})
db.posts.updateOne({author: '小米'},{更新內(nèi)容})
db.posts.updateMany()
定義:用于更新多條數(shù)據(jù)
db.posts.updateMany({author:"張三"},{$set:{author:"無所謂"}})
db.posts.undate({},{$set:{"phone": '1390124'}},b1,b2)
- b1為true時(shí)表示 在沒有匹配到記錄時(shí)創(chuàng)建一個(gè)新的記錄运挫。false:不創(chuàng)建新記錄
- b2為true表示批量 false表示一個(gè)
單詞in 單詞out
1.表示在....里面 1.表示在。套耕。谁帕。外面 在外面
2.流行 最in的 2.過時(shí)的、淘汰的
data updata
1.日期 1.最新的
2.what data today 2.更新