diff --git a/employees.json b/employees.json new file mode 100644 index 0000000..6ed2165 --- /dev/null +++ b/employees.json @@ -0,0 +1,187 @@ +[ + { + "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 + } + ] + } +] \ No newline at end of file diff --git a/queries.js b/queries.js index 99f09c5..f91595c 100644 --- a/queries.js +++ b/queries.js @@ -4,4 +4,34 @@ print('Employees') // List all the employees. print('1. List all Employees') -db.employees.find({}).forEach(printjsononeline) \ No newline at end of file +db.employees.find({}).forEach(printjsononeline) + +//Find the employee with whose name is Steve. +db.employees.find({"name": "Steve"}) + +//Find all employees whose age is greater than 30. +db.employees.find({"age": { $gt: 30}}) + +//Find the employee whose extension is 2143. +db.employees.find({"phone.ext": "2143"}) + +//Find all employees that are over 30. +db.employees.find({"age": { $gt: 30}}) + +//Find all employees that are less than or equal to 30. +db.employees.find({"age": { $lte: 30}}) + +//Find all the employees whose favorite food is pizza. +db.employees.find({"favorites.food": "pizza"}) + +//Change Willy’s personal phone number to "93-123-45-67". +db.employees.updateOne({"name": "Willy"}, { $set: { 'phone.personal': "93-123-45-67" } }) + +//Change Bob’s privilege to normal user. +db.employees.updateOne({"name": "Bob"}, { $set: { "privileges": "user" } }) + +//Find all employees whose favorite artist is equal to Picasso. +db.employees.find({"favorites.artist": "Picasso"}) + +//Delete the user John. +db.employees.deleteOne({"name": "John"}) \ No newline at end of file