# W1Day03-MongoDB.Shell ![](https://img.shields.io/badge/Created_Date-12_Apr_2022-orange) :::info - 【題目】https://hackmd.io/@hexschool/HkQTj4rQ5 ::: ### 1 :::info 依以下格式新增 1 筆 document 到 `students` collection ```json { "studentName": "Riley Parker", "group": "A", "score": 83, "isPaid": false } ``` ::: ```=sh db.students.insertOne({ "studentName": "Riley Parker", "group": "A", "score": 83, "isPaid": false }) ``` --- ### 2 :::info 直接新增多筆 document 到 students collection ::: ```=sh db.students.insertMany([ { "studentName": "Brennan Miles", "group": "C", "score": 72, "isPaid": false }, { "studentName": "Mia Diaz", "group": "B", "score": 98, "isPaid": true }, { "studentName": "Caroline morris", "group": "B", "score": 55, "isPaid": false }, { "studentName": "Beverly Stewart", "group": "B", "score": 60, "isPaid": false } ]) ``` --- ### 3 :::info 查詢 students collection 中的所有資料 ::: ```=sh db.students.find().pretty() ``` --- ### 4 :::info - 查詢 students collection - 符合 group 屬性為 B 的資料 - 使用 `{ <field>: <value> }` 設定符合的項目 ::: ```=sh db.students.find({ "group": "B" }).pretty() ``` --- ### 5 :::info - 查詢 students collection - 符合分數在 60 分以上的的資料 ::: ```=sh db.students.find( { "score": { $gt: 60 } } ).pretty() ``` --- ### 6 :::info - 查詢 students collection - 符合分數在 60 分以下、或是 group 為 B 的資料 ::: ```=shell db.students.find( { "$or": [ { "score": { "$lt": 60 } }, { "group": "B" } ] } ).pretty() ``` ![](https://i.imgur.com/pgR9jnI.png) --- {%hackmd RAtn1iEBRO2tCbZeA-NylQ %}