Giter Club home page Giter Club logo

u2_lab_mongodb_sneakers's Introduction

MongoDB Sneaker Exercise

AirForce1s

Overview

In this lab, we'll used what we learned about working in the mongo shell to practice interacting with a new database of sneakers.

Getting started

  • Fork and Clone
  • Open in VSCode so you can paste your answers into the ReadMe
  • Open Terminal
  • Tighten those laces

Instructions

Below is an array of objects:

const products = [
  { model: "4281", brand: "Nike", color: "Red" },
  { model: "4363", brand: "Nike", color: "Black" },
  { model: "4365", brand: "Nike", color: "White" },
  { model: "4490", brand: "Nike", color: "White" },
  { model: "130014", brand: "Nike", color: "Cream" },
  { model: "4361", brand: "Nike", color: "White" },
  { model: "130169", brand: "Nike", color: "Teal" },
  { model: "4401", brand: "Nike", color: "Maroon" },
  { model: "130182", brand: "Nike", color: "Gold" },
]

Let's start by connecting to the mongo interactive shell:

mongosh

Next, let's create a new database:

use sneakersDatabase

Cool, now let's populate our products database with products. Let's start by creating a products collection, then using insertMany to insert multiple documents:

db.products.insertMany([
  { model: "4281", brand: "Nike", color: "Red" },
  { model: "4363", brand: "Nike", color: "Black" },
  { model: "4365", brand: "Nike", color: "White" },
  { model: "4490", brand: "Nike", color: "White" },
  { model: "130014", brand: "Nike", color: "Cream" },
  { model: "4361", brand: "Nike", color: "White" },
  { model: "130169", brand: "Nike", color: "Teal" },
  { model: "4401", brand: "Nike", color: "Red" },
  { model: "4281", brand: "Nike", color: "Gold" },
])

Let's confirm that this insert many operation worked:

db.products.find({})

We should see all our products in our database.

Exercise

Use the MongoDB lesson to solve for the following:

  1. Find all the Air Jordans that have the model number: 4363.
<--- solution goes here !--->
  1. Find all shoes that are either red or black.
<--- solution goes here !--->
  1. Insert 4 new Air Jordans into our collection (you can just make up model #s and colors if you like):
<--- solution goes here !--->
  1. Update all red Jordans to Maroon:
<--- solution goes here !--->
  1. Delete all model 4281 Air Jordans.
<--- solution goes here !--->

Bonus

Create a better representation of a "product".

Maybe a product should have size, and size should be an array of sizes or perhaps a product should have a quantity.

For example:

{ model: "4281", brand: "Nike", color: "Red", sizes: [7,8,9,10,11], qty: 36 },

Once you have a better representation of a product, apply the changes to every product in the database.

Write your queries below:

<--- solution goes here !--->

Jordan

Resources

u2_lab_mongodb_sneakers's People

Contributors

nobodyslackey avatar ahonore42 avatar anpato avatar ben-manning avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.