最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

一、 數(shù)據(jù)庫使用

開啟 mongodb 服務(wù):要管理數(shù)據(jù)庫,必須先開啟服務(wù),開啟服務(wù)使用 

mongod --dbpath  c:\mongodb

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

mongo

清屏:

cls

查看所有數(shù)據(jù)庫列表

show dbs

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

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

use student

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

插入一條數(shù)據(jù)

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

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

show collections

刪除數(shù)據(jù)庫,刪除當(dāng)前所在的數(shù)據(jù)庫

db.dropDatabase();

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

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

三、插入(增加)數(shù)據(jù)

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

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

四、查找數(shù)據(jù)

1 、查詢所有記錄

db.userInfo.find();

相當(dāng)于:select* from userInfo;
2 、查詢?nèi)サ艉蟮漠?dāng)前聚集集合中的某列的重復(fù)數(shù)據(jù)

db.userInfo.distinct("name");

會過濾掉 name 中的相同數(shù)據(jù)
相當(dāng)于:select distict name from userInfo;
3 、查詢 age = 22 的記錄

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

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

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

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

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

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

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

相當(dāng)于: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 的數(shù)據(jù) 模糊查詢用于搜索

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

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

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

相當(dāng)于:select * from userInfo where name like ‘mongo%’;

11 、查詢指定列 name 、age 數(shù)據(jù)

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

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

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

相當(dāng)于: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 的數(shù)據(jù)

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

相當(dāng)于:select * from userInfo where name = ‘zhangsan’ and age = ‘22’;
15 、查詢前 5 條數(shù)據(jù)

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

相當(dāng)于:selecttop 5 * from userInfo;
16 、查詢 10 條以后的數(shù)據(jù)

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

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

五、刪除數(shù)據(jù)

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 }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Mongodb中MapReduce實現(xiàn)數(shù)據(jù)聚合方法詳解

    Mongodb中MapReduce實現(xiàn)數(shù)據(jù)聚合方法詳解

    Mongodb是針對大數(shù)據(jù)量環(huán)境下誕生的用于保存大數(shù)據(jù)量的非關(guān)系型數(shù)據(jù)庫,針對大量的數(shù)據(jù)。接下來通過本文給大家介紹Mongodb中MapReduce實現(xiàn)數(shù)據(jù)聚合方法詳解,感興趣的朋友一起學(xué)習(xí)吧
    2016-05-05
  • mongodb實現(xiàn)同庫聯(lián)表查詢方法示例

    mongodb實現(xiàn)同庫聯(lián)表查詢方法示例

    在關(guān)系型數(shù)據(jù)庫中,通過連接運算符可以實現(xiàn)多個表聯(lián)合查詢。而非關(guān)系型數(shù)據(jù)庫的特點是表之間屬于弱關(guān)聯(lián),下面這篇文章主要給大家介紹了關(guān)于mongodb實現(xiàn)同庫聯(lián)表查詢的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-08-08
  • win7平臺快速安裝、啟動mongodb的方法

    win7平臺快速安裝、啟動mongodb的方法

    這篇文章主要介紹了win7平臺快速安裝、啟動mongodb的方法,結(jié)合圖文形式分析了win7平臺下載、安裝、啟動、配置MongoDB數(shù)據(jù)庫的方法與注意事項,需要的朋友可以參考下
    2020-05-05
  • Mongodb實戰(zhàn)之全文搜索功能

    Mongodb實戰(zhàn)之全文搜索功能

    全文檢索對每一個詞建立一個索引,指明該詞在文章中出現(xiàn)的次數(shù)和位置,當(dāng)用戶查詢時,檢索程序就根據(jù)事先建立的索引進行查找,并將查找的結(jié)果反饋給用戶的檢索方式。下面這篇文章主要給大家介紹了Mongodb全文搜索功能的相關(guān)資料,需要的朋友可以參考下。
    2017-07-07
  • 解決MongoDB?位置查詢報錯planner?returned?error:?unable?to?find?index?for?$geoNear?query的問題

    解決MongoDB?位置查詢報錯planner?returned?error:?unable?to?find

    這篇文章主要介紹了MongoDB位置查詢報錯planner?returned?error:?unable?to?find?index?for?$geoNear?query的解決方案,需要的朋友可以參考下
    2023-08-08
  • MongoDB數(shù)據(jù)庫索引用法詳解

    MongoDB數(shù)據(jù)庫索引用法詳解

    本文詳細講解了MongoDB數(shù)據(jù)庫索引的用法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-07-07
  • MongoDB 模式設(shè)計詳解

    MongoDB 模式設(shè)計詳解

    這篇文章主要介紹了MongoDB 模式設(shè)計詳解的相關(guān)資料,需要的朋友可以參考下
    2022-12-12
  • mongodb數(shù)據(jù)庫入門之CURD簡單操作示例

    mongodb數(shù)據(jù)庫入門之CURD簡單操作示例

    這篇文章主要介紹了mongodb數(shù)據(jù)庫入門之CURD簡單操作,結(jié)合簡單示例形式分析了MongoDB數(shù)據(jù)庫基本的CURD增刪改查相關(guān)操作技巧與注意事項,需要的朋友可以參考下
    2019-10-10
  • 基于?MongoTemplate實現(xiàn)MongoDB的復(fù)雜查詢功能

    基于?MongoTemplate實現(xiàn)MongoDB的復(fù)雜查詢功能

    本文介紹了如何使用MongoTemplate進行復(fù)雜的MongoDB查詢,展示了如何進行分頁和排序查詢,通過示例代碼,展示了如何處理不同類型的查詢,如單條件查詢、模糊查詢、組合條件查詢以及分頁排序查詢,感興趣的朋友跟隨小編一起看看吧
    2024-12-12
  • MongoDB備份和還原的操作指南

    MongoDB備份和還原的操作指南

    MongoDB備份和還原是指將MongoDB數(shù)據(jù)庫中的數(shù)據(jù)和集合備份到另一個存儲位置,并在需要的時候恢復(fù)這些備份的過程,備份和還原MongoDB數(shù)據(jù)庫非常重要,本文給大家介紹了MongoDB備份和還原的操作指南,需要的朋友可以參考下
    2024-05-05

最新評論

隆尧县| 江孜县| 财经| 通州区| 巴彦淖尔市| 海晏县| 辉南县| 象山县| 历史| 习水县| 宜兴市| 磐石市| 道真| 青冈县| 江安县| 商水县| 慈溪市| 千阳县| 遂川县| 普定县| 海盐县| 来凤县| 甘孜| 遂昌县| 花垣县| 新绛县| 泉州市| 河源市| 安宁市| 电白县| 察雅县| 韶关市| 定陶县| 离岛区| 林西县| 方山县| 廊坊市| 大港区| 永善县| 南陵县| 大渡口区|