亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

MongoDB實現創(chuàng)建刪除數據庫、創(chuàng)建刪除表(集合 )、數據增刪改查

 更新時間:2022年06月26日 15:23:24   作者:小旭2021  
這篇文章介紹了MongoDB實現創(chuàng)建刪除數據庫、創(chuàng)建刪除表(集合 )、數據增刪改查的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

一、 數據庫使用

開啟 mongodb 服務:要管理數據庫,必須先開啟服務,開啟服務使用 

mongod --dbpath  c:\mongodb

管理 mongodb 數據庫:(一定要在新的 cmd 中輸入)

mongo

清屏:

cls

查看所有數據庫列表

show dbs

二、 創(chuàng)建數據庫

使用數據庫、創(chuàng)建數據庫

use student

如果真的想把這個數據庫創(chuàng)建成功,那么必須插入一個數據。
數據庫中不能直接插入數據,只能往集合(collections)中插入數據。不需要專門創(chuàng)建集合,只
需要寫點語法插入數據就會創(chuàng)建集合:

插入一條數據

db.student.insert({“name”:”xiaoming”});

db.student 系統發(fā)現 student 是一個陌生的集合名字,所以就自動創(chuàng)建了集合。
顯示當前的數據集合(mysql 中叫表)

show collections

刪除數據庫,刪除當前所在的數據庫

db.dropDatabase();

刪除集合,刪除指定的集合 刪除表
刪除集合

db.COLLECTION_NAME.drop()
db.user.drop()

三、插入(增加)數據

插入數據,隨著數據的插入,數據庫創(chuàng)建成功了,集合也創(chuàng)建成功了。

db. 表名.insert({"name":"zhangsan"}); student 集合名稱(表)

四、查找數據

1 、查詢所有記錄

db.userInfo.find();

相當于:select* from userInfo;
2 、查詢去掉后的當前聚集集合中的某列的重復數據

db.userInfo.distinct("name");

會過濾掉 name 中的相同數據
相當于:select distict name from userInfo;
3 、查詢 age = 22 的記錄

db.userInfo.find({"age": 22});

相當于: select * from userInfo where age = 22;
4 、查詢 age > 22 的記錄

db.userInfo.find({age: {$gt: 22}});

相當于:select * from userInfo where age >22;
5 、查詢 age < 22 的記錄

db.userInfo.find({age: {$lt: 22}});

相當于:select * from userInfo where age <22;
6 、查詢 age >= 25 的記錄

db.userInfo.find({age: {$gte: 25}});

相當于:select * from userInfo where age >= 25;
7 、查詢 age <= 25 的記錄

db.userInfo.find({age: {$lte: 25}});

8 、查詢 age >= 23 并且 age <= 26 注意書寫格式

db.userInfo.find({age: {$gte: 23, $lte: 26}});

9 、查詢 name 中包含 mongo 的數據 模糊查詢用于搜索

db.userInfo.find({name: /mongo/});

相當于:%%
select * from userInfo where name like ‘%mongo%’;
10 、查詢 name 中以 mongo 開頭的

db.userInfo.find({name: /^mongo/});

相當于:select * from userInfo where name like ‘mongo%’;

11 、查詢指定列 name 、age 數據

db.userInfo.find({}, {name: 1, age: 1});

相當于:select name, age from userInfo;
當然 name 也可以用 true 或 false,當用 ture 的情況下河 name:1 效果一樣,如果用 false 就是排除 name,顯示 name 以外的列信息。
12 、查詢指定列 name 、age 數據, age > 25

db.userInfo.find({age: {$gt: 25}}, {name: 1, age: 1});

相當于:select name, age from userInfo where age >25;
13 、按照年齡排序 1 升序 -1 降序

升序:db.userInfo.find().sort({age: 1});
降序:db.userInfo.find().sort({age: -1});

14 、查詢 name = zhangsan, age = 22 的數據

db.userInfo.find({name: 'zhangsan', age: 22});

相當于:select * from userInfo where name = ‘zhangsan’ and age = ‘22’;
15 、查詢前 5 條數據

db.userInfo.find().limit(5);

相當于:selecttop 5 * from userInfo;
16 、查詢 10 條以后的數據

db.userInfo.find().skip(10);

相當于:select * from userInfo where id not in ( select top 10 * from userInfo );

五、刪除數據

db.collectionsNames.remove( { "borough": "Manhattan" } )
db.users.remove({age: 132});
By default, the remove() method removes all documents that match the remove condition. Use
the justOne option to limit the remove operation to only one of the matching documents.
db.restaurants.remove( { "borough": "Queens" }, { justOne: true }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Win10 安裝 MongoDB 3.6.5 失敗的問題及解決方法

    Win10 安裝 MongoDB 3.6.5 失敗的問題及解決方法

    這篇文章主要介紹了Win10 安裝 MongoDB 3.6.5 失敗的問題及解決方法,需要的朋友可以參考下
    2018-05-05
  • MongoDB利用oplog恢復數據的方法

    MongoDB利用oplog恢復數據的方法

    這篇文章主要介紹了MongoDB利用oplog恢復數據的方法,當我們對數據出現誤操作的時候,可以利用oplog恢復數據,下文操作過程需要的小伙伴可以參考一下
    2022-04-04
  • 關于NoSQL之MongoDB的一些總結

    關于NoSQL之MongoDB的一些總結

    這篇文章主要介紹了關于NoSQL之MongoDB的一些總結的相關資料,需要的朋友可以參考下
    2015-07-07
  • mongoDB分頁的兩種方法(圖例)

    mongoDB分頁的兩種方法(圖例)

    mongoDB分頁的兩種方法,mongoDB的分頁查詢是通過limit(),skip(),sort()這三個函數組合進行分頁查詢的。
    2013-11-11
  • MongoDB特定類型的查詢語句實例

    MongoDB特定類型的查詢語句實例

    在關系型數據庫中,可以實現基于表的各種各樣的查詢,下面這篇文章主要給大家介紹了關于MongoDB特定類型查詢的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-04-04
  • MongoDB錯誤32-bit servers don''t have journaling enabled by default解決方法

    MongoDB錯誤32-bit servers don''t have journaling enabled by de

    這篇文章主要介紹了MongoDB錯誤32-bit servers don't have journaling enabled by default解決方法,需要的朋友可以參考下
    2014-10-10
  • MongoDB 模式設計詳解

    MongoDB 模式設計詳解

    這篇文章主要介紹了MongoDB 模式設計詳解的相關資料,需要的朋友可以參考下
    2022-12-12
  • 關于MongoTemplate通過id查詢?yōu)閚ull的問題

    關于MongoTemplate通過id查詢?yōu)閚ull的問題

    這篇文章主要介紹了關于MongoTemplate通過id查詢?yōu)閚ull的問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • MongoDB??數據模型的設計模式及優(yōu)缺點

    MongoDB??數據模型的設計模式及優(yōu)缺點

    這篇文章主要介紹了MongoDB??數據模型的設計模式,在實際開發(fā)中,大多數性能問題都可以追溯到糟糕的模型設計,官方也提供分享過文檔模型設計的進階技巧,這里簡單翻譯記錄一下,需要的朋友可以參考下
    2022-12-12
  • MongoDB教程之基本管理命令

    MongoDB教程之基本管理命令

    這篇文章主要介紹了MongoDB教程之基本管理命令,本文講解了啟動和停止MongoDB、服務器狀態(tài)監(jiān)控兩部份內容,需要的朋友可以參考下
    2015-05-05

最新評論