├── Slides.key ├── relationships.js ├── README.md ├── docker-compose.yaml ├── sample-node-app.js ├── schema-validation.js └── students.js /Slides.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amigoscode/mongodb-course/HEAD/Slides.key -------------------------------------------------------------------------------- /relationships.js: -------------------------------------------------------------------------------- 1 | student = { 2 | "firstName": "Retha", 3 | "lastName": "Killeen", 4 | "email": "rkilleen0@amigoscode.com", 5 | "gender": "F", 6 | "address": [ 7 | ObjectId("60a14726117491202884550e"), 8 | ObjectId("60a14745117491202884550f") 9 | ], 10 | "isStudentActive": false, 11 | "favouriteSubjects": [ 12 | "maths", 13 | "english", 14 | "it" 15 | ], 16 | "totalSpentInBooks": 0.00 17 | } 18 | 19 | address = { 20 | "country": "Philippines", 21 | "postCode": "PL90", 22 | "city": "Manila" 23 | } 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MongoDB Course 2 | 3 | https://amigoscode.com/courses/mongodb 4 | ![2](https://user-images.githubusercontent.com/40702606/118755471-cf58b300-b860-11eb-979a-16d263b320a8.png) 5 | 6 | MongoDB is a very popular for any project. It's a no sql database which offers high performance and scalability. Having MongoDB in your skills set will set you apart from the competition. You will be able to build backend applications super fast. 7 | 8 | - ✅ In this course you will learn 9 | - ✅ What is Mongo 10 | - ✅ Running Mongo on Docker 11 | - ✅ Documents and Collections 12 | - ✅ Queries 13 | - ✅ Indexes 14 | - ✅ Data Modeling 15 | - ✅ Cursors 16 | - ✅ Database Administration 17 | - ✅ Build NodeJS backend Application backed by Mongo 18 | - ✅ How to Create a MongoDB cluster running on AWS 19 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3.8" 2 | services: 3 | mongodb: 4 | image: mongo 5 | container_name: mongodb 6 | ports: 7 | - 27017:27017 8 | volumes: 9 | - data:/data 10 | environment: 11 | - MONGO_INITDB_ROOT_USERNAME=rootuser 12 | - MONGO_INITDB_ROOT_PASSWORD=rootpass 13 | mongo-express: 14 | image: mongo-express 15 | container_name: mongo-express 16 | restart: always 17 | ports: 18 | - 8081:8081 19 | environment: 20 | - ME_CONFIG_MONGODB_ADMINUSERNAME=rootuser 21 | - ME_CONFIG_MONGODB_ADMINPASSWORD=rootpass 22 | - ME_CONFIG_MONGODB_SERVER=mongodb 23 | volumes: 24 | data: {} 25 | 26 | networks: 27 | default: 28 | name: mongodb_network 29 | -------------------------------------------------------------------------------- /sample-node-app.js: -------------------------------------------------------------------------------- 1 | const MongoClient = require('mongodb').MongoClient; 2 | 3 | const username = "amigoscode"; 4 | const cluster = "amigoscodecluster0"; 5 | const database = "amigoscode"; 6 | const password = "RGJDuhFqHrBWskjT"; 7 | const db = "amigoscode" 8 | const collections = { 9 | student: "student" 10 | } 11 | 12 | const uri = `mongodb+srv://${username}:${password}@${cluster}.yecee.mongodb.net/${database}?retryWrites=true&w=majority`; 13 | const client = new MongoClient( 14 | uri, { useNewUrlParser: true, useUnifiedTopology: true }); 15 | 16 | async function main() { 17 | try { 18 | await client.connect(); 19 | console.log("Connected to db...") 20 | const collection = client.db(db).collection(collections.student); 21 | const cursor = await collection.find(); 22 | await cursor.forEach(console.log) 23 | 24 | } catch (error) { 25 | console.log(error); 26 | } finally { 27 | client.close(); 28 | } 29 | } 30 | 31 | main(); 32 | 33 | -------------------------------------------------------------------------------- /schema-validation.js: -------------------------------------------------------------------------------- 1 | db.createCollection("student_with_validation", { 2 | validator: { 3 | $jsonSchema: { 4 | bsonType: "object", 5 | required: [ 6 | "firstName", "lastName", "country", "isStudentActive", 7 | "email", "totalSpentInBooks", "gender" 8 | ], 9 | properties: { 10 | firstName: { 11 | bsonType: "string", 12 | description: "must be a string and is required", 13 | }, 14 | lastName: { 15 | bsonType: "string", 16 | description: "must be a string and is required", 17 | }, 18 | country: { 19 | bsonType: "string", 20 | description: "must be a string and is required", 21 | }, 22 | isStudentActive: { 23 | bsonType: "bool", 24 | description: "must be a bool and is required" 25 | }, 26 | gender: { 27 | enum: ["M", "F"], 28 | description: "can only be one of the enum values and is required", 29 | }, 30 | favouriteSubjects: { 31 | bsonType: "array", 32 | description: "favourite subject is required", 33 | }, 34 | totalSpentInBooks: { 35 | bsonType: "double", 36 | description: "must be a double if the field exists", 37 | }, 38 | email: { 39 | bsonType : "string", 40 | pattern : "@amigoscode\.com$", 41 | description: "must be a string and match the regular expression pattern" 42 | }, 43 | }, 44 | }, 45 | } 46 | }); 47 | -------------------------------------------------------------------------------- /students.js: -------------------------------------------------------------------------------- 1 | student = { 2 | "firstName": "Retha", 3 | "lastName": "Killeen", 4 | "email": "rkilleen0@mysql.com", 5 | "gender": "F", 6 | "country": "Philippines", 7 | "isStudentActive": false, 8 | "favouriteSubjects": [ 9 | "maths", 10 | "english", 11 | "it" 12 | ], 13 | "totalSpentInBooks": 0.00 14 | } 15 | 16 | students = [ 17 | { 18 | "firstName": "Retha", 19 | "lastName": "Killeen", 20 | "email": "rkilleen0@mysql.com", 21 | "gender": "F", 22 | "country": "Philippines", 23 | "isStudentActive": false, 24 | "favouriteSubjects": [ 25 | "maths", 26 | "english", 27 | "it" 28 | ], 29 | "totalSpentInBooks": 100.00 30 | }, 31 | { 32 | "firstName": "Coraline", 33 | "lastName": "Langham", 34 | "email": "clangham1@globo.com", 35 | "gender": "F", 36 | "country": "Philippines", 37 | "isStudentActive": true, 38 | "favouriteSubjects": [], 39 | "totalSpentInBooks": 5.00 40 | }, 41 | { 42 | "firstName": "Ario", 43 | "lastName": "Frye", 44 | "email": "afrye2@blogs.com", 45 | "gender": "M", 46 | "country": "Argentina", 47 | "isStudentActive": true, 48 | "favouriteSubjects": [ 49 | "science", 50 | "history" 51 | ], 52 | "totalSpentInBooks": 0.00 53 | }, 54 | { 55 | "firstName": "Sandye", 56 | "lastName": "Iddens", 57 | "email": "siddens3@spiegel.de", 58 | "gender": "F", 59 | "country": "France", 60 | "isStudentActive": true, 61 | "favouriteSubjects": [ 62 | "it" 63 | ], 64 | "totalSpentInBooks": 0.00 65 | }, 66 | { 67 | "firstName": "Lynn", 68 | "lastName": "Antonsson", 69 | "email": "lantonsson4@yelp.com", 70 | "gender": "F", 71 | "country": "Indonesia", 72 | "isStudentActive": true, 73 | "favouriteSubjects": [ 74 | "computer science", 75 | "it", 76 | "maths" 77 | ], 78 | "totalSpentInBooks": 0.00 79 | }, 80 | { 81 | "firstName": "Fabe", 82 | "lastName": "Chartman", 83 | "email": "fchartman5@reuters.com", 84 | "gender": "M", 85 | "country": "Angola", 86 | "isStudentActive": false, 87 | "favouriteSubjects": [ 88 | "history" 89 | ], 90 | "totalSpentInBooks": 66.00 91 | }, 92 | { 93 | "firstName": "Nealon", 94 | "lastName": "Tabord", 95 | "email": "ntabord6@devhub.com", 96 | "gender": "M", 97 | "country": "Greece", 98 | "isStudentActive": false, 99 | "favouriteSubjects": [ 100 | "maths" 101 | ], 102 | "totalSpentInBooks": 0.00 103 | }, 104 | { 105 | "firstName": "Jule", 106 | "lastName": "Brough", 107 | "email": "jbrough7@wix.com", 108 | "gender": "M", 109 | "country": "Russia", 110 | "isStudentActive": true, 111 | "favouriteSubjects": [ 112 | "english", 113 | "science" 114 | ], 115 | "totalSpentInBooks": 100.00 116 | }, 117 | { 118 | "firstName": "Mufinella", 119 | "lastName": "Sansun", 120 | "email": "msansun8@google.com", 121 | "gender": "F", 122 | "country": "China", 123 | "isStudentActive": false, 124 | "favouriteSubjects": [ 125 | "science" 126 | ], 127 | "totalSpentInBooks": 0.00 128 | }, 129 | { 130 | "firstName": "Cally", 131 | "lastName": "Walkden", 132 | "email": "cwalkden9@craigslist.org", 133 | "gender": "F", 134 | "country": "Niger", 135 | "isStudentActive": true, 136 | "favouriteSubjects": [ 137 | "it" 138 | ], 139 | "totalSpentInBooks": 165.00 140 | } 141 | ] --------------------------------------------------------------------------------