關於mongo的一些常用命令

2021-10-20 08:09:05 字數 3840 閱讀 5229

最近一直使用的mongodb資料庫,在使用中用到的一些命令做個記錄,方便以後檢視

事務超時設定為***秒:

db.admincommand()

修改預設記憶體配置

【分頁查詢快取超出32m後會報錯使用此命令解決或給字段加索引】

db.admincommand()

插入db.getcollection(『user』).insert();

mongodb更新命令【將id為11的資料email屬性改為123,age屬性改為12】

db.getcollection(『user』).update(,});

模糊查詢

db.getcollection(『user』).find();

以條件開頭:db.getcollection(『user』).find();

以條件結尾:db.getcollection(『user』).find();

select * from user where name like 「%條件%」

拷貝資料庫

db.copydatabase(『ngiam-db』, 『ngiam-db-bat』);

刪除資料庫(拷貝改名、刪除原庫)

db.copydatabase(『old_name』, 『new_name』);

use old_name

db.dropdatabase();

大於:katex parse error: expected '}', got 'eof' at end of input: …).find(});

大於等於:katex parse error: expected '}', got 'eof' at end of input: …).find(});

小於:katex parse error: expected '}', got 'eof' at end of input: …).find(});

小於等於:katex parse error: expected '}', got 'eof' at end of input: …ind(});

不等於:katex parse error: expected '}', got 'eof' at end of input: …ind(})

select * from user where number != 15;

等於:$eq(等效於直接條件查詢)

檢視mongo配置設定

use admin

db.runcommand()

判斷乙個字段是否存在

db.cited_*****s_new.find(

' at position 14: exists': true}̲, # title2t…exists』: false}} # result的第乙個值:不存在

)// 查詢manager不為空的使用者並按照最後修改時間倒序

db.getcollection(『userentity』).find(', got 'eof' at end of input: and:[},}]}).sort()

語句in

db.getcollection(『user』).find (})

select * from user where number in(11,222)

語句and

db.getcollection(『user』).find(,「age」:})

select * from user where name like = 「liu%」 and age >=10

語句or

db.getcollection(『user』).find($or:[,]);

select * from user where name = 『liu』 or ctest = 『mongodb』;

時間查詢

db.getcollection(『user』).find(', got 'eof' at end of input: …z"),"modtime":}});

select * from user where create > 『2019-10-10 9:23.23』 and modtime <= 『2019-10-18 10:23.19』;

db.getcollection(『userentity』).find(' at position 26: …e("2020-11-10")}̲}) 2020-11-10之…and:[' at position 26: …e("2020-11-23")}̲},})

sort公升序

db.getcollection(『user』).find().sort();

select * from user order by age asc

sort降序

db.getcollection(『user』).find().sort();

select * from user order by age desc

count語句

db.getcollection(『user』).find().count();

select count(1) from user where 『user』 = 『a』;

備份mongo資料庫

mongodump -u ***賬號 -p ***密碼 -h 127.0.0.1 -d 資料庫名db -o /home/備份檔案位址

恢復mongo資料庫

mongorestore -h <:port> --drop -d dbname

/–dir

mongorestore -h 127.0.0.1:27017 --drop -d 庫名 --dir d:\mgodb\db\abc 檔案位址

–host <:port>, -h <:port>:

–db , -d :

需要恢復的資料庫例項,例如:test,當然這個名稱也可以和備份時候的不一樣,比如test2

–drop:

恢復的時候,先刪除當前資料,然後恢復備份的資料。就是說,恢復後,備份後新增修改的資料都會被刪除,慎用哦! :

mongorestore 最後的乙個引數,設定備份資料所在位置,例如:c:\data\dump\test。

你不能同時指定

和 --dir 選項,–dir也可以設定備份目錄。

–dir:

指定備份的目錄

你不能同時指定

和 --dir 選項

mongodb庫表資料匯出

mongoexport -h 172.16.17.160:27017 -u *** -p *** -d 庫名db -c 表名 --type=json -o /home/data/abc.json

將int型別轉換為string型別

db.usernameentity.find(}).foreach(function(x));

mongodb update 的用法:

db.table_name.update(where,setnew,issert,multi );

引數解釋:

where:類似於sql中的update 語句where後邊的查詢條件

setnew:類似於sql中update語句中set後邊的部分,也就是你要更新的部分

upsert:如果要更新的那條記錄沒有找到,是否插入一條新紀錄,預設為false不插入,true為插入

multi :是否更新滿足條件的多條的記錄,false:只更新第一條,true:更新多條,預設為false

示例:

db.sms_user.update(,},f

alse,true);

相當於:

update sms_user set adduser="",nickname="",area="" where state=0;

更新表sms_user中所有state=0的記錄

ok===

關於git的一些常用命令

1.更新 git pull 2.新增提交 git add path 提交單個檔案的路徑 git add js 提交所有的js檔案 git add 提交所有的檔案 2.本地提交 git commit m 注釋 3.提交到伺服器 git push 4.檢視遠端分支 git branch a 5 檢視本地...

關於git的一些常用命令

本地建立庫並提交到遠端庫上 設定使用者名稱 git config global user.name x 檢視設定資訊 git config list 注 1.直接輸入git config global user.name或git config global user.email後回車也可以檢視nam...

關於git的一些常用命令

1 git status 檢視當前在哪個分支,是用來檢視工作目錄當前狀態的指令 2 git add 將所有檔案提交到暫存區 git add shopping list.txt 將單獨乙個檔案提交到暫存區 3 git commit m 新增一些描述 提交到本地倉庫 4 git push 提交到線上倉庫...