重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
由于習慣了使用關系型數據庫,覺得SQL語句對數據進行操作的靈活性不用多說,也很好理解和掌握,但是開始用MongoDB后,在客戶端命令行中對一些數據進行操作時總是很別扭,總是提示語法錯誤,盡管RockMongo或MongoVUE等工具 提供了很多便利,但有些操作還是需要命令行操作,于是將在命令行中的數據操作命令做了個大概的總結:
堅守“ 做人真誠 · 做事靠譜 · 口碑至上 · 高效敬業 ”的價值觀,專業網站建設服務10余年為成都成都墻體彩繪小微創業公司專業提供企業網站建設營銷網站建設商城網站建設手機網站建設小程序網站建設網站改版,從內容策劃、視覺設計、底層架構、網頁布局、功能開發迭代于一體的高端網站建設服務。
1.查看命令提示
db.help();
db.collname.help();
db.collname.find().help();
re.help();
2.切換創建數據庫
use dbname;
3.查詢所有數據庫
show dbs;
4.刪除當前使用的數據庫
db.dropDataBase();
5.創建集合(table)
db.createCollection("name",{size:1,capped:5,max:100});
6.查詢
db.table.find() 相當于:select * from table
db.table.distinct("name") 相當于:select distinct name from table;
db.table.find({"age":22}) 相當于:select * from table where age=22;
db.table.find({"age":{$gte:22}}) 相當于 select * from table where age>=22;
db.table.find({"age":{$lt:22}}) 相當于 select * from table where age<22;
db.table.find({"age":22},{"name":1}) 相當于 select name from table where age=22
db.table.find({"age":{$gt:10,$lt:30}}) 相當于 select * from table where age>10 and age<=30
db.table.find({"name":/mary/});相當于 select * from table where name like '%mary%'
7.新增
db.table.save({name:1,age:1}); 相當于insert into table (name,age) values (1,1);
8.修改
db.table.update({age:1},{$set:{name:mary}},false,true) 相當于update table set name=mary where age=1
9.刪除
db.table.remove({age:1}) 相當于 delete from table where age=1