skip to content
HDip Data Analytics
Export to PDF
46376 - Web App Development
46887 - Thinking with Algorithms
51308 - Computer Architecture
52167 - Programming and Scripting
52465 - Programming for Data Analysis
52553 - Applied Databases
52446 - Fundamentals of Data Analysis
Last Three Module Sep 2019
SVG Demo - Stack diagram
SVG Demo - Sorting flow
Links and downloads
Table of Contents
MongoDB Quickref Sheet
Query, Update, Options
Topic 6 - MongoDB I
Why NoSQL Databases?
MongoDB, JSON and BSON
MongoDB Rules for creating a Document
Create a document - save()
Query the database - find()
Topic 7 - MongoDB II
More on find()
__Relationships__ in MongoDB
One-to-One relationships with embedded documents
One-to-Many Relationships with Embedded Documents
One-to-Many relationships with document References
Embedded Documents vs Referenced Documents
MongoDB vs MySQL
Applied Databases - Topic 6
1. Create a mongodb database called usersdb
2. Create a collection called users which has documents with the following attributes:
3. Give the command to find all documents in the users collection.
4. Give the command to find all documents in the users collection where the age is 19.
5. Give the command to find all documents in the users collection where the age is greater than 19.
6. Give the command to find all documents in the users collection where the age is greater than 19 and the user has a car.
7. Give the command to find all documents in the users collection where _id is greater than 104 and age is greater than 20.
8. Give the command to find the first document in the users collection where the user has a car.
9. User 106 - Shane has bought a car with reg 12-G-1234.
10. User 102 - Aine has bought a car with reg 10-G-9876.
11. User 105 – Bill’s document is as follows:
12. User 106’s document now looks as follows:
13. Give the mongodb command to add 1 to each user’s age.
14. Add a new attribute sex, to each document as follows:
15. Add a new attribute title with the value Mr., to each document where the sex is M, and the age is greater than 20:
16. Users 101 – Sean, 103 – Alan and 107 – Will have sold their cars, update the collection to remove the carReg attribute from these documents.
17. Give the mongodb command to list/show only the fname, surname, age and sex attributes of documents where the _id is between 101 and 107 inclusive.
18. Give the mongodb command to rename the fname attribute to Name.
19. Export the userdb.users to a json file
Applied Databases - Topic 7
1. Import lab7.json to MongoDB.
2. Show the name and population of all cities where the population is over 10,000.
3. Show the name and population of each state based on the cities shown.
4. Show the total population of cities in NY as “Population”.
5. Show the _id, city and name of the capital city of each state for cities with a population greater than 20,000.
6. Show all details for “Tom” including full details of his addresses.
7. Show all details for “Chesterfield” including full details of the state, but do not show details relating to its capital.
This is an old revision of the document!
· Last modified: 2019/04/07 09:39 by
Export to PDF
Back to top
Except where otherwise noted, content on this wiki is licensed under the following license:
CC Attribution-Share Alike 4.0 International