標籤:bsp 指定 分享圖片 查詢 分享 通過 com span 取資料
- 查詢所有
sql: select * from table_name
mongodb: db.getCollection(‘期刊論文‘).find({})
如所示,擷取期刊論文collection 下的所有 資料
條件查詢
注意: 請注意選擇列的資料類型
1. journal _title = ‘ Nature‘
sql: select * from table_name where journal_title = ‘Nature‘
mongodb: db.getCollection(‘期刊論文‘).find({"journal_title": "Nature"})
2. volume<495:
sql: select * from table_name where volume< 495;
mongodb: db.getCollection(‘期刊論文‘).find({"volume":{$lt:"495"}}).pretty()
3. volume <= 495
sql: select * from table_name where volume<= 495;
mongodb: db.getCollection(‘期刊論文‘).find({"volume":{$lte:"495"}}).pretty()
4. volume >495
sql: select * from table_name where volume> 495;
mongodb: db.getCollection(‘期刊論文‘).find({"volume":{$gt:"495"}}).pretty()
5. volume !=495
sql: select * from table_name where volume!= 495;
mongodb: db.getCollection(‘期刊論文‘).find({"volume":{$ne:"495"}}).pretty()and, or 查詢
6. and 查詢:
sql: select * from table_name where journal_title = ‘Nature‘ and vulome> 495;
mongodb: db.getCollection(‘期刊論文‘).find({"journal_title":"Nature","volume":{$gt:"495"}}).pretty()
7. or 查詢:
sql: select * from table_name where journal_title = ‘Nature‘ or vulome> 495;
mongodb: db.getCollection(‘期刊論文‘).find({$or: [ {"journal_title":"Nature"},{"volume":{$gt:"495"}}]}).pretty()
8. and 和 or 聯集查詢:
sql: select * from table_name where volume>52 and journal_title = ‘Nature‘ or journal_title = ‘Meccanica‘;
mongodb: db.getCollection(‘期刊論文‘).find({"volume":{$gt:‘52‘},$or: [ {"journal_title":"Nature"},{"journal_title":"Meccanica"}]}).pretty()
MongoDB 查詢整理