Question

In: Computer Science

Task 2 (1 mark) Transformation of data stored in the relational tables into data stored in...

Task 2 (1 mark) Transformation of data stored in the relational tables into data stored in BSON collection.

Solutions

Expert Solution

Mapping Tables, Rows and Columns

Each database in MongoDB consists of collections which are equivalent to an RDBMS database consisting of SQL tables. Each collection stores data in the form of documents which is equivalent to tables storing data in rows. While a row stores data in its set of columns, a document has a JSON-like structure (known as BSON in MongoDB). Lastly, the way we have rows in an SQL row, we have fields in MongoDB. Following is an example of a document (read row) having some fields (read columns) storing user data:

1

2

3

4

5

6

7

{

"_id": ObjectId("5146bb52d8524270060001f3"),

"age": 25,

"city": "Los Angeles",

"email": "[email protected]",

"user_name": "Mark Hanks"

}

This document is equivalent to a single row in RDBMS. A collection consists of many such documents just as a table consists of many rows. Note that each document in a collection has a unique _id field, which is a 12-byte field that serves as a primary key for the documents. The field is auto generated on creation of the document and is used for uniquely identifying each document.

To understand the mappings better, let us take an example of an SQL table users and its corresponding structure in MongoDB. As shown in Fig 1, each row in the SQL table transforms to a document and each column to a field in MongoDB.

MongoDB uses the find method which is equivalent to the SELECT command in SQL. The following statements simply read all the documents from the posts collection.

1

2

3

SQL: SELECT * FROM `posts`

MongoDB: db.posts.find()


Related Solutions

The advantages of a relational database include limiting the amount of redundant data that are stored...
The advantages of a relational database include limiting the amount of redundant data that are stored in a database. Why is this an important advantage? What can go wrong when redundant data are stored?
Part #4: Data normalization: Background: Data in a relational database is stored in a normalized form....
Part #4: Data normalization: Background: Data in a relational database is stored in a normalized form. Data normalization or just normalization is a strategy used to organize data into multiple related tables to reduce data redundancy while preserving data integrity. Exercise: Normalize the student data in the University table (sample data is shown further below) into 3 tables, namely, Student, Department, and Course. You do not need to populate data. Just illustrate the schema for the 3 tables. You may...
Task 1 Write a program that adds the three numbers stored in data registers at 0x20,...
Task 1 Write a program that adds the three numbers stored in data registers at 0x20, 0x30, and 0x40 and places the sum in data register at 0x50 task 4 Modify the program in Task1, so the program will run in infinite loop by using these following functions: GOTO function BRA function CALL function Simulate your program in PIC18 IDE Simulator and attach a screenshot of your simulation while the program is running.
Create an ER diagram, a Relational Schema, and tables with Data, based on the following requirements:...
Create an ER diagram, a Relational Schema, and tables with Data, based on the following requirements: The database will keep track of students and campus organizations. - For each student, we will keep track of his or her unique student ID, and his or her name and gender. - For each organization, we will keep track of its unique organization ID and the location. - Each student in the database belongs to at least one organization and can belong to...
Differentiate between types of table and the data stored in these tables (Master, Transaction, and Reference...
Differentiate between types of table and the data stored in these tables (Master, Transaction, and Reference tables)
QUESTION: The following tables describe the content of a relational database: a) Identify and classify the...
QUESTION: The following tables describe the content of a relational database: a) Identify and classify the tables as either entity or relationship The first step in building an E-R model is to identify the entities. Having identified the entities, the next step is to identify all the relationships that exist between these entities. Using the content of the relational database above: b) Using the relations in the relational database, explain how one can transform relationship in E-R model into a...
What are the different options for converting a subtype-supertype hierarchy to relational tables?
What are the different options for converting a subtype-supertype hierarchy to relational tables?
Use MYSQL to create the set of database tables of the relational database model and complete...
Use MYSQL to create the set of database tables of the relational database model and complete the associated queries given. Procedure: 1) Write all the SQL statements, necessary to create all tables and relationships, with Primary & Foreign keys. 2) Execute each statement in the correct order to create the relational database in MYSQL. 3)Insert some data into each table. 4) Use all your SQL create and Insert statements (from MS Word) to execute in the MYSQL WorkBench 5) Write...
Give examples of social, task, transformation and transactional leadership styles.
Give examples of social, task, transformation and transactional leadership styles.
Explain the differences among hierarchical, network, and relational data models. What makes the relational data model...
Explain the differences among hierarchical, network, and relational data models. What makes the relational data model the most popular data model in use today? (DQ 4-1)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT