溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MongoDB使用總結系列2

發布時間:2020-07-28 03:04:51 來源:網絡 閱讀:399 作者:xmanliang 欄目:MongoDB數據庫

 由于習慣了使用關系型數據庫,覺得SQL語句對數據進行操作的靈活性不用多說,也很好理解和掌握,但是開始用MongoDB后,在客戶端命令行中對一些數據進行操作時總是很別扭,總是提示語法錯誤,盡管RockMongo或MongoVUE等工具 提供了很多便利,但有些操作還是需要命令行操作,于是將在命令行中的數據操作命令做了個大概的總結:

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

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女