angularjs增删改查数据_MongoDB数据读写操作(增删改查)总结
《大數據和人工智能交流》頭條號向廣大初學者新增C 、Java 、Python 、Scala、javascript 等目前流行的計算機、大數據編程語言,希望大家以后關注本頭條號更多的內容。
一、在執行mongo.exe文件后,進入MongoDB的shell 操作
1、創建一個數據庫
use users
2、查看所有數據庫 (驗證上面的創建的數據庫是否存在,顯示結果為不存在)
show dbs
3、向users插入數據
db.users.insert({sid:"s001",sname:"lily"});
show dbs
4、刪除數據庫users
use users
db.dropDatabase()
5、在 test 數據庫中創建 users 集合:
db.createCollection("users")
6、查看所有文檔
show collections
或者show tables
二、使用insert() 或 save() 方法向集合中插入文檔
1、插入一維結構的數據
db.goods.insert({goods_id:"g001",gname:"MongoDB",gprice:110});
db.goods.insert({goods_id:"g002",gname:"HBase",gprice:120});
db.goods.insert({goods_id:"g003",gname:"Redis",gprice:130});
2 插入二維結構的數據
db.goods.insert({goods_id:"g006",gname:"spark006",gprice:60,join:{e_mail:"lily006@126.com",tel:"13211111116"}});
db.goods.insert({goods_id:"g007",gname:"spark007",gprice:70,join:{e_mail:"lily007@126.com",tel:"13211111117"}});
db.goods.insert({goods_id:"g008",gname:"spark008",gprice:80,join:{e_mail:"lily008@126.com",tel:"13211111118"}});
3、插入數組結構的數據
db.goods.insert({goods_id:"g009",gname:"spark009",gprice:90,gtype:['book','water']});
三、使用update() 方法用于更新已存在的文檔
步驟1:執行db.goods.find() 查看以前操作過的記錄
在前面插入的如下記錄中執行更新操作,如未插入記錄請先插入記錄:
db.goods.insert({goods_id:"g003",gname:"Redis",gprice:130});
步驟2:將 gname值更新為“MySQL”
db.goods.update({goods_id:"g003",gname:"MySQL",gprice:130});
步驟3:以格式化的方式查看更新后的結果
db.goods.find().pretty()
四、使用remove()方法刪除文檔
步驟1:對某一文檔執行2次操作
db.goods.insert({goods_id:"g011",gname:"Redis",gprice:110});
db.goods.insert({goods_id:"g011",gname:"Redis",gprice:110});
步驟2:使用 find() 函數查看操作結果:
db.goods.find()
步驟3:移除 goods_id:為 'g011' 的文檔:
db.goods.remove({' goods_id ':' g011'})
db.goods.find()
五、 find()查找操作
步驟1:向文檔中插入數據
db.goods.insert({goods_id:"g012",gname:"spark012",gprice:120,gtype:['book','water']});
步驟2:查找所有記錄
db.goods.find()
步驟3:查找一條記錄
db.goods.findOne();
步驟4:按照編號查找記錄
db.goods.find({goods_id:"g012"});
db.goods.findOne({goods_id:"g012"});
《大數據和人工智能交流》的宗旨
1、將大數據和人工智能的專業數學:概率數理統計、線性代數、決策論、優化論、博弈論等數學模型變得通俗易懂。
2、將大數據和人工智能的專業涉及到的數據結構和算法:分類、聚類 、回歸算法、概率等算法變得通俗易懂。
3、最新的高科技動態:數據采集方面的智能傳感器技術;醫療大數據智能決策分析;物聯網智慧城市等等。
根據初學者需要會有C語言、Java語言、Python語言、Scala函數式等目前主流計算機語言。
根據讀者的需要有和人工智能相關的計算機科學與技術、電子技術、芯片技術等基礎學科通俗易懂的文章。
總結
以上是生活随笔為你收集整理的angularjs增删改查数据_MongoDB数据读写操作(增删改查)总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux离线安装python3 dev
- 下一篇: epoll哪些触发模式_网络编程:epo