網站首頁 編程語言 正文
一、數(shù)據(jù)庫相關
1.切換/創(chuàng)建數(shù)據(jù)庫
>use “dbname”;
2.查詢所有數(shù)據(jù)庫
> show dbs; mytest ?0.000GB
3.查看當前使用的數(shù)據(jù)庫
> db.getName();
Mytest
4.查看數(shù)據(jù)庫版本
> db.version();
4.2.8
5.查看當前db的鏈接地址
> db.getMongo();
connection to 127.0.0.1:27017
二、用戶相關
1、創(chuàng)建普通用戶(創(chuàng)建用戶cg,對mytest數(shù)據(jù)庫讀寫權限)
> db.createUser({user:"cg",pwd:"lianshi",roles:[{role:"readWrite",db:"mytest"}]})
2、刪除用戶>db.dropUser("yonghu")
3、修改用戶密碼
db.updateUser("cg",{pwd:"123456"})
4、進入數(shù)據(jù)mytest,用戶名密碼認證
> db.auth("cg","lianshi");
三、集合Collection相關
1.獲得數(shù)據(jù)聚合(表)
> db.getCollectionNames(); [ "student" ]
2. 集合(表)插入數(shù)據(jù)
db.student.insert({"id":"2","name":"yxy"})
3.查詢數(shù)據(jù)
> db.student.find(); { "_id" : ObjectId("5eef61f3447efbc4346fbb9b"), "id" : "2", "name" : "yxy" } { "_id" : ObjectId("5eef61fe447efbc4346fbb9c"), "id" : "1", "name" : "hmf" } { "_id" : ObjectId("5eeff9582e8cdcf5c32c0ecf"), "id" : "3", "name" : "yx" } 相當于:select* from student;
4.查詢唯一字段值
> db.student.distinct("name"); [ "hmf", "yx", "yxy" ]
會過濾掉name中的相同數(shù)據(jù)
相當于:select distict name from student;
5.查詢name?= yxy的記錄
> db.student.find({"name":"yxy"}); { "_id" : ObjectId("5eef61f3447efbc4346fbb9b"), "id" : "2", "name" : "yxy" } { "_id" : ObjectId("5ef077145c4ca32ccc787893"), "id" : "2", "name" : "yxy" }
相當于: select * from student where name?= “yxy”;
6.插入int32字段類型的數(shù)據(jù)
db.student.insert({"id":NumberInt(1234567),"name":"hu"});
7、插入int64字段類型數(shù)據(jù)
db.student.insert({"age":NumberLong(22),"name":"hu"});
8、插入Decimal字段類型數(shù)據(jù)
db.student.insert({"va":NumberDecimal("22.3"),"name":"hu"});
9、查詢語句
db.student.find({}) ???.projection({}) ???.sort({_id:-1}) ???.limit(100)
10、刪除(集合)表
db.student.drop();
參考:https://www.jb51.net/article/48217.htm
原文鏈接:https://blog.csdn.net/fen_fen/article/details/106906344
相關推薦
- 2022-09-22 為什么float4個字節(jié)比long8個字節(jié)所表示的數(shù)值范圍廣
- 2022-07-25 pandas實現(xiàn)數(shù)據(jù)讀取&清洗&分析的項目實踐_python
- 2023-06-21 Python輸出列表(List)不帶中括號和引號的問題及解決方法_python
- 2022-09-26 shell變量,shell函數(shù),shell數(shù)組,shell常用命令,shell流程控制語句
- 2022-03-23 Asp.Net?Core?使用Monaco?Editor?實現(xiàn)代碼編輯器功能_實用技巧
- 2022-01-31 pytorch:tensor與numpy轉換 & .cpu.numpy()和.numpy()
- 2022-09-15 Python實現(xiàn)圖形用戶界面計算器_python
- 2022-04-15 關于pyinstaller生成.exe程序報錯:缺少.ini文件的分析_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支