章節連結
初接觸 Mongo DB,就順帶記錄一下常常用到的查詢指令 – db.collection.find() 的用法。
指令結構:
db.collection.db({條件 – 物件屬性},{鍵指定 – 想要顯示的欄位 – 物件屬性})
基本操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
當 collection 名稱為 restaurants 時: // 查詢全部資料 db.restaurants.find() db.restaurants.find({ }) // 顯示特定欄位資料,預設顯示為1,不顯示為0 db.restaurants.find({},{location:1}) // 排序,1為由小到大,-1為由大到小 db.restaurants.find().sort({rating:-1}) // 比較操作 db.restaurants.find({$or: [{ "category": "中東料理" }, { "category": "日式料理" }]}) //當然,你也可以加上其他操作符號,像是: $gt (>), $gte (>=), $in (包含), $lt (<), $lte (<=), $ne (!=), $nin(不包含) $and (&&), $nor(不符合), $not(不包含), $or (||) |
延伸閱讀
- [指南] Amazon Amplify 初探 – 佈署一個結合身分認證的 Vue.js 應用
- [筆記] AlphaCamp 不只是刷題的 Leetcode 訓練營 – 4
- [筆記] TypeScript + D3.js + Vue 3 – 幫長條圖加上基本的水平、垂直軸 ( x, y axis)
- [筆記] HiSKIO 2020 Vue3 專業職人 入門篇 – 7
- [指南] npm 預設下載來源更改 – 因應中國的特殊規矩
GA瀏覽人氣:18