In: Computer Science
The database design process for noSQL databases is different from one for relational (SQL) databases.
As we learned noSQL database does not require to have a predefined structure, except of creating a list of databases and the list of collections. Some of the noSQL databases (like MongoDB) allow to define certain rules that will define what should be the structure of the acceptable documents for each collection.
As you may recall, when you need to store multiple data points in a relational database you use multiple records (rows) where each record and then values to describe properties of that record will be placed in the columns. Unlike relational databases, noSQL databases allow two ways of storing multiple values (lists):
The choice between one or another is based on the potential size of the list, size of the records, and the most common operations the database will need to process. The rule of thumb will be if the list changes regularly and each item in the list or complex (an object itself), not very well connected to the other items, or the list is very long, then use one document per record approach. Note, that the size of the document may also be limited (e.g. 15MB for a MongoDB document).
If the list is small, it has with small records, and unlikely change often, then you can make it as a part of one document.
For example, if you have a database of the business transactions, and there could be millions of those transactions recorded per minute, create a new document for each of them with me more efficient choice. In contrary, when you store information about degrees that an employee earned, which will be updated rarely, all degrees can be combined into a list in one employee profile document.
MongoDB also allows to use relational database – like relations, by using a document id as a value in another document.
You may read more about best practices of MongoDB design (Links to an external site.).
Business Case
A car-sharing company decided to use a MongoDB noSQL database to store information about their primary operations, which include recording of all rides, real time car locations, and users. A ride defined as combination of pick-up location, drop-off locations (if the car has been returned), with the associated timestamps of the those events.
Directions
In this assignment, you will propose a database structure for the given business case. It should include the list of collections, and one sample document (in JSON format) for each collection to demonstrate the document structure.
Put the list of the collections with the comments on their role along with the sample documents in JSON format in a single .txt file and submit it.
The following three collections are proposed :-
(Please ignore the type of values of keys. I am stating them as empty strings for my own convinience. Actually, they ought to be treated with common knowledge. For example, PIN will be an integer and so on.)
1) User Collection - It has all the required information about all the users
{
"users":{
"userId":"",
"registered":"",
"name":{
"firstName":"",
"middleName":"",
"lastName":""
},
"contactNo":{
"value":"",
"verified":""
},
"emailId":{
"value":"",
"verified":""
},
"paymentMethods":[
{
"cards":{
"cardNo":"",
"cvv":"",
"type":""
},
"onlineWallets":[
{
"name":"",
"verified":""
}
]
}
],
"homeAddress":{
"coordinates":"",
"address-line1":"",
"address-line2":"",
"city":"",
"state":"",
"landmark":"",
"country":"",
"pin":""
},
"savedAddresses":[
{
"coordinates":"",
"address-line1":"",
"address-line2":"",
"city":"",
"state":"",
"landmark":"",
"country":"",
"pin":""
}
]
}
}
2) Rides Collection - It has all the required information about all the rides happening.
{
"rides":[
{
"userId":"",
"pickupData":{
"location":{
"coordinates":"",
"addressLine1":"",
"addressLine2":"",
"city":"",
"state":"",
"landmark":"",
"country":"",
"pin":""
},
"time":""
},
"dropoff":{
"location":{
"coordinates":"",
"addressLine1":"",
"addressLine2":"",
"city":"",
"state":"",
"landmark":"",
"country":"",
"pin":""
},
"time":""
},
"paymentMethod":"",
"vehicle":{}
}
]
}
3) Real Time LocationCollection - It has all the required information about all the real time locations of the cars.
{
"real-time-locations":[
{
"vehicleId":"",
"locationTimestamp":"",
"duration":"",
"coordinates":"",
"addressLine1":"",
"addressLine2":"",
"city":"",
"state":"",
"landmark":"",
"country":"",
"pin":""
}
]
}
Other similar collections that could be made are vehicle information etc.