Skip to content

Instantly share code, notes, and snippets.

@rschpdr
Forked from sandrabosk/check-mongo-shell.md
Created July 2, 2020 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rschpdr/3593cce408c661492cd4cc5234461f1d to your computer and use it in GitHub Desktop.
Save rschpdr/3593cce408c661492cd4cc5234461f1d to your computer and use it in GitHub Desktop.
  1. create a new database - name it company:
> use company
  1. Add all the employees listed below to the database company, in the collection employees:
> db.employees.insertMany([ /* paste here the list given below */ ])
# list of employees:

{
 name: "Sue",
 age: 19,
 phone: {
  personal: "555-123-123",
  work: "555-456-456",
  ext: "2342"
 },
 privileges: "user",
 favorites: { artist: "Picasso", food: "pizza" },
 finished: [ 17, 3 ],
 badges: [ "blue", "black" ],
 points: [
    { points: 85, bonus: 20 },
    { points: 85, bonus: 10 }
 ]
},
{
 name: "Bob",
 age: 42,
 phone: {
  personal: "555-123-123",
  work: "555-456-456",
  ext: "7673"
 },
 privileges: "admin",
 favorites: { artist: "Miro", food: "meringue" },
 finished: [ 11, 25 ],
 badges: [ "green" ],
 points: [
    { points: 85, bonus: 20 },
    { points: 64, bonus: 12 }
 ]
},
{
 name: "Willy",
 age: 22,
 phone: {
  personal: "555-123-123",
  work: "555-456-456",
  ext: "8263"
 },
 privileges: "user",
 favorites: { artist: "Cassatt", food: "cake" },
 finished: [ 6 ],
 badges: [ "blue", "Picasso" ],
 points: [
    { points: 81, bonus: 8 },
    { points: 55, bonus: 20 }
 ]
},
{
 name: "John",
 age: 34,
 phone: {
  personal: "555-123-123",
  work: "555-456-456",
  ext: "2143"
 },
 privileges: "admin",
 favorites: { artist: "Chagall", food: "chocolate" },
 finished: [ 5, 11 ],
 badges: [ "Picasso", "black" ],
 points: [
    { points: 53, bonus: 15 },
    { points: 51, bonus: 15 }
 ]
},
{
 name: "Steve",
 age: 23,
 phone: {
  personal: "555-123-123",
  work: "555-456-456",
  ext: "8253"
 },
 privileges: "user",
 favorites: { artist: "Noguchi", food: "nougat" },
 finished: [ 14, 6 ],
 badges: [ "orange" ],
 points: [
    { points: 71, bonus: 20 }
 ]
},
{
 name: "Martin",
 age: 43,
 phone: {
  personal: "555-123-123",
  work: "555-456-456",
  ext: "5623"
 },
 privileges: "user",
 favorites: { food: "pizza", artist: "Picasso" },
 finished: [ 18, 12 ],
 badges: [ "black", "blue" ],
 points: [
    { points: 78, bonus: 8 },
    { points: 57, bonus: 7 }
 ]
}
  1. Perform the following queries:
  • List all the employees
  • Find the employee whose name is Steve
  • Find all employees whose age is greater than 30
  • Update the age of Sue to 20.
  • Change Bob’s privilege to the regular user.
  • Delete the user John.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment