From b988f0cff87d166d402b77cb511068a0988e39dc Mon Sep 17 00:00:00 2001 From: Juan Cruz Date: Sat, 1 Jul 2023 15:20:15 +0200 Subject: [PATCH] done --- datasets/queries.js | 38 ++++++++++++++++++++++++++++++++++++++ queries.js | 7 ------- 2 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 datasets/queries.js delete mode 100644 queries.js diff --git a/datasets/queries.js b/datasets/queries.js new file mode 100644 index 0000000..4137119 --- /dev/null +++ b/datasets/queries.js @@ -0,0 +1,38 @@ + + + +//employes +print('Employees') + + +// 2. Import: + mongosh --eval "const db = db.getSiblingDB('work'); db.dropDatabase(); const data = require('C:/Users/jcruz/OneDrive/IronHack/modulo2/mongo-examples/datasets/employees.json'); db.getCollection('employees').insertMany(data);" + +//3. List all the employees. + +db.employees.find().pretty() + +// 4. connect to mongo shell +{mongosh --eval "use Works"} + +// 5. Find the employee with whose name is Steve. +{ name : "Steve"} + +// Find all employees whose age is greater than 30. +{ age: { $gt: 30 } } +// Find the employee whose extension is 2143. +{ extension: 2143 } +// Find all employees that are over 30. +{ age: { $gt: 30 } } +// Find all employees that are less than or equal to 30. +{ age: { $lte: 30 } } +// Find all the employees whose favorite food is pizza. +{ "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. +{ "favorites.artist": "Picasso" } +// Delete the user John. +db.employees.deleteOne({ name: "John" }) \ No newline at end of file diff --git a/queries.js b/queries.js deleted file mode 100644 index 99f09c5..0000000 --- a/queries.js +++ /dev/null @@ -1,7 +0,0 @@ - - -print('Employees') - -// List all the employees. -print('1. List all Employees') -db.employees.find({}).forEach(printjsononeline) \ No newline at end of file