mongodb 常用語句 查詢操作

2021-09-01 15:29:43 字數 1261 閱讀 6846

查詢所有資料

db.songs.find();

查第一條

db.songs.findone();

去重某列(分組)

db.songs.distinct("id");

等值查詢

db.songs.find();

db.songs.find();

db.songs.find(); (語法錯誤)

db.songs.find(); (匹配id是字串)

非等值查詢

db.songs.find(});

db.songs.find(});

db.songs.find(});

db.songs.find(});

db.songs.find(});

db.songs.find(});

包含查詢

db.songs.find(});

db.songs.find(});

db.songs.find(});

db.songs.find();(包含a)

db.songs.find();(以a開頭)

查詢結果指定列

db.songs.find({},); (只顯示name列)

db.songs.find({},); (顯示name和id兩列)

排序(1:asc,-1:desc)

db.songs.find().sort();

db.songs.find().sort();

db.songs.find().sort();

分頁 limit是pagesize,skip是第幾頁*pagesize

db.songs.find().sort().limit(1);

db.songs.find().sort().skip(1).limit(1);

or查詢

db.songs.find(,]})

db.songs.find(,}]})

db.songs.find(},}]});

and查詢

db.songs.find(,]})

db.songs.find(,}]})

db.songs.find(},}]});

<>

db.songs.find(});

indb.songs.find(});

選擇特定列(0=false,!0=true)

db.songs.find(},);

db.songs.find(},);

mongodb常用語句

連線遠端資料庫 mongo 192.168.1.100 27017 db1 u username p password 備份資料 mongodump h 127.0.0.1 27017 d db1 c table1 q o d bak d 需要備份資料庫 c 需要備份的ollection 可選,不傳...

mongodb 常用語句 集合操作

檢視集合幫助 db.songs.help 檢視集合總資料量 db.songs.count 檢視表空間大小 db.songs.datasize 檢視集合所在資料庫 db.songs.getdb 建立集合 集合中必須產生過資料 db.music db.music.insert db.music.coun...

MongoDB中常用語句

delete 刪除 刪除乙個集合 db.collection.deleteone 刪除多個集合 db.collection.deletmany remove 刪除 刪除所有的name 李四的資料 db.student.remove 只刪除一條 男的資料 僅刪除一條 db.student.remove...