好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > MongoDB數據庫基礎操作總結

MongoDB數據庫基礎操作總結

熱門標簽:crm外呼系統聯系方式 小裙科技電銷機器人怎樣 長沙電銷外呼防封卡是什么 外呼線路資源屬于電信業務嗎 青白江400企業電話申請 河南電話外呼系統招商 內蒙古營銷智能外呼系統哪個好 智能外呼系統官網 呼和浩特外呼系統原理是什么

本文實例講述了MongoDB數據庫基礎操作。分享給大家供大家參考,具體如下:

1.創建數據庫

>use test
 
> db.test.insert({"name":1})
  • 插入之后才能查到test

2.查看數據庫

>show dbs

3.刪除數據庫

> use test
 
> db.dropDatabase()

4.創建集合

4.1 集合概念

  • 集合就是一組文檔,相當于多條記錄。
> db.title.insert({"name":"hyx"})
  • 插入之后即創建集合

5.查看集合

> show collections

6.刪除集合

>use test
 
>db.title.drop()

7.插入文檔

7.1 文檔概念

  • 多個鍵及其關聯的值有序地放置在一起就是文檔。
  • 文檔類似于json數據
> db.file.insert({name:"huangyuxin",age:11})

8.查看文檔

>db.files.find()

9.變量方式插入文檔

> document=({by:"hyx"})
{ "by" : "hyx" }
> db.file.insert(document)
WriteResult({ "nInserted" : 1 })
> db.file.find()
{ "_id" : ObjectId("5c6e8a060fc535200b893f29"), "name" : "huangyuxin", "age" : 11 }
{ "_id" : ObjectId("5c6e8b1c0fc535200b893f2a"), "by" : "hyx" }
>

10.同時插入多條

> var res = db.file.insertMany([{"b": 3}, {'c': 4}])
> res
{
    "acknowledged" : true,
    "insertedIds" : [
        ObjectId("5c6e8bba0fc535200b893f2b"),
        ObjectId("5c6e8bba0fc535200b893f2c")
    ]
}
> db.file.find()
{ "_id" : ObjectId("5c6e8a060fc535200b893f29"), "name" : "huangyuxin", "age" : 11 }
{ "_id" : ObjectId("5c6e8b1c0fc535200b893f2a"), "by" : "hyx" }
{ "_id" : ObjectId("5c6e8bba0fc535200b893f2b"), "b" : 3 }
{ "_id" : ObjectId("5c6e8bba0fc535200b893f2c"), "c" : 4 }
>

11.更新文檔

> db.file.update({"name":"huangyuxin"},{$set:{"name":"hyx"}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.file.find()
{ "_id" : ObjectId("5c6e8a060fc535200b893f29"), "name" : "hyx", "age" : 11 }
{ "_id" : ObjectId("5c6e8b1c0fc535200b893f2a"), "by" : "hyx" }
{ "_id" : ObjectId("5c6e8bba0fc535200b893f2b"), "b" : 3 }
{ "_id" : ObjectId("5c6e8bba0fc535200b893f2c"), "c" : 4 }
{ "_id" : ObjectId("5c6e8cdf0fc535200b893f2d"), "name" : "hyx" }
>
> db.file.save({"_id" : ObjectId("5c6e8b1c0fc535200b893f2a"),"name":"hyx"})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.file.find()
{ "_id" : ObjectId("5c6e8a060fc535200b893f29"), "name" : "hyx", "age" : 11 }
{ "_id" : ObjectId("5c6e8b1c0fc535200b893f2a"), "name" : "hyx" }
{ "_id" : ObjectId("5c6e8bba0fc535200b893f2b"), "b" : 3 }
{ "_id" : ObjectId("5c6e8bba0fc535200b893f2c"), "c" : 4 }
{ "_id" : ObjectId("5c6e8cdf0fc535200b893f2d"), "name" : "hyx" }
>

12.刪除文檔

12.1刪除指定文檔

> db.title.find()
{ "_id" : ObjectId("5c6e89060fc535200b893f27"), "name" : "yx" }
> db.file.find()
{ "_id" : ObjectId("5c6e8a060fc535200b893f29"), "name" : "hyx", "age" : 11 }
{ "_id" : ObjectId("5c6e8b1c0fc535200b893f2a"), "name" : "hyx" }
{ "_id" : ObjectId("5c6e8bba0fc535200b893f2b"), "b" : 3 }
{ "_id" : ObjectId("5c6e8bba0fc535200b893f2c"), "c" : 4 }
{ "_id" : ObjectId("5c6e8cdf0fc535200b893f2d"), "name" : "hyx" }
> db.file.remove({"b":3})
WriteResult({ "nRemoved" : 1 })
> db.file.find()
{ "_id" : ObjectId("5c6e8a060fc535200b893f29"), "name" : "hyx", "age" : 11 }
{ "_id" : ObjectId("5c6e8b1c0fc535200b893f2a"), "name" : "hyx" }
{ "_id" : ObjectId("5c6e8bba0fc535200b893f2c"), "c" : 4 }
{ "_id" : ObjectId("5c6e8cdf0fc535200b893f2d"), "name" : "hyx" }
>

12.2刪除全部文檔

>db.file.deleteMany({})

12.3刪除多個文檔

>db.file.deleteMany({ status : 1 })
  • 刪除當前庫所有status 等于 1 的文檔

13.條件表達式

13.1$gt 大于

  • 查詢age 大于 0 的數據
> db.title.find({age:{$gt : 0}})
{ "_id" : ObjectId("5c6f7d633ea8783bbfb7fd5e"), "age" : 10 }
>

13.2 $lt 小于

13.3 $gte 大于等于 $lte 小于等于

  • 查詢age 大于等于 0 的數據
> db.title.find({age:{$gte : 1}})

13.4 大于小于

> db.title.find({age:{$lt:13,$gt:10}})
{ "_id" : ObjectId("5c6f7ded3ea8783bbfb7fd5f"), "age" : 12 }
{ "_id" : ObjectId("5c6f7e833ea8783bbfb7fd60"), "age" : 12 }
>

13.5 $ne 不等于 $eq 等于

14. $type操作符

  • $type操作符是基于BSON類型來檢索集合中匹配的數據類型,并返回結果。

> db.title.find({"name" : {$type : 2}})
{ "_id" : ObjectId("5c6e89060fc535200b893f27"), "name" : "yx" }
>

15. limit()

  • 查詢指定條數
> db.title.find().limit(2)
{ "_id" : ObjectId("5c6e89060fc535200b893f27"), "name" : "yx" }
{ "_id" : ObjectId("5c6f7d633ea8783bbfb7fd5e"), "age" : 10 }
>
  • 第一個 {} 放 where 條件,為空表示返回集合中所有文檔。
  • 第二個 {} 指定那些列顯示和不顯示 (0表示不顯示 1表示顯示)。
> db.title.find({},{"name":1,_id:0}).limit(1)
{ "name" : "yx" }
>

16.skip() 

  • 跳過幾條數據
  • 不要輕易使用Skip來做查詢,否則數據量大了就會導致性能急劇下降,這是因為skip是一條一條的數過來的,多了自然就慢了。

17.sort()

  •  1 為升序排列,而 -1 是用于降序排列。
> db.title.find({},{'age':1,_id:0}).sort({age:1})
{ }
{ "age" : 10 }
{ "age" : 12 }
{ "age" : 12 }
> db.title.find({},{'age':1,_id:0}).sort({age:-1})
{ "age" : 12 }
{ "age" : 12 }
{ "age" : 10 }
{ }
>

18.索引

18.1 創建單個索引

  • 1 為指定按升序創建索引,降序索引指定為 -1
>db.title.createIndex({"age":1})

18.2 創建多個索引

>db.title.createIndex({"name":1,"age":-1})

18.3 查看索引

>db.col.getIndexes()

18.4 查看索引大小

>db.col.totalIndexSize()

18.5 刪除所有集合索引

>db.col.dropIndexes()

18.6 刪除指定索引

>> db.title.dropIndex({'age':1})
{ "nIndexesWas" : 2, "ok" : 1 }
>

希望本文所述對大家MongoDB數據庫程序設計有所幫助。

您可能感興趣的文章:
  • vs2019 下用 vb.net編寫窗體程序連接 mongodb4.2的方法
  • .Net Core使用MongoDB的詳細教程
  • python爬蟲用mongodb的理由
  • python爬蟲數據保存到mongoDB的實例方法
  • JAVA代碼實現MongoDB動態條件之分頁查詢
  • MongoDB CRUD操作中的插入實例教程
  • 如何使用Docker安裝一個MongoDB最新版
  • Java MongoDB實現REST過程解析

標簽:舟山 菏澤 安順 白山 呼倫貝爾 池州 楚雄 黃石

巨人網絡通訊聲明:本文標題《MongoDB數據庫基礎操作總結》,本文關鍵詞  MongoDB,數據庫,基礎,操作,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《MongoDB數據庫基礎操作總結》相關的同類信息!
  • 本頁收集關于MongoDB數據庫基礎操作總結的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 太湖县| 国产麻豆精品一区二区三区91 | 把她日出水了好紧太爽了视频| 一级夫妻黄色片| 亚洲精品久久一区二区三区777| 大伊香蕉在线精品不卡视频| 超级乱淫伦短篇在车上| 川越唯哺乳奶水在线观看| 国产视频入口| 91麻豆传传媒波多野衣久久看| 最近中文字幕高清2018-2019中文字幕 | 娇妻被别人破了处绿帽| 国人免费无码区久久久免费| 薛婧闺魅| 网爆门在线观看| 免费的app软件下载| 图片区小说区区亚洲五月| 舒淇拍三级在线观看| 美女隐私无遮挡网站| 麻豆免费版在线| 香蕉久久综合精品首页| freesexoldwoman性欧美| 午夜精品视频一区二区三区在线看| の教室の成熟した女教师| 国产精品黄在线观看免费| 美女啪啪网站| 欧美成人禁片在线观看俄罗斯| 金银瓶4| 日本ⅩXX色在线观看软件| 公与丰满媳1一15| 色偷偷噜噜噜亚洲男人| 欧美性色福利视频在线观看| 成人午夜视频免费观看| 3p两男一女双龙挺进在线| 男女边摸边吃奶边做爽免费视频| 国产91在线看| 欧美老熟妇性生交大片A片斗地主| 老色鬼成人VA在线观看| avhd在线观看| 国产精品亚洲一区在线播放| a视频免费在线观看|