DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. The Classic Northwind Database Converted to the NoSQL World

The Classic Northwind Database Converted to the NoSQL World

We take a look at how to convert Microsoft's classic relational Northwind database to a NoSQL-based database — in this case, restdb.io.

Jon Erik Solheim user avatar by
Jon Erik Solheim
·
Jun. 22, 17 · Tutorial
Like (6)
Save
Tweet
Share
14.12K Views

Join the DZone community and get the full member experience.

Join For Free

northwind

This blog post uses the classical Northwind example from Microsoft to show how you can migrate from a traditional relational database to a NoSQL cloud database.

Northwind Traders Access database is a sample database that shipped with Microsoft Office suite. The Northwind database contains the sales data for a fictitious company called Northwind Traders, which imports and exports specialty foods from around the world. Developers (back in the 90s) used it to learn the MS Access product.

In the following example we will show how to:

  • Import the original SQL data files.
  • Map relations between tables (collections).
  • Use the REST API to the new Northwind NoSQL database.

Original Data Model

The Northwind relational data schema is shown in the picture below. 13 tables and 13 relations, we will try to re-create this in a modern NoSQL document schema.

model

Behold the UI from the Access database.

access

Uploading the Raw Data

Thanks a GitHub project we found, we save time and get a nice set of CSV files from a data dump from the Northwind database.

Importing the data is easy. Just click the Import button on the restdb.io database dashboard.

The screen shot below shows the import of orders and the mapping of the data fields.

import

After we've imported all data files, we can see the newly created collections and the count of their data records. All in all, it counts 6,635 records (or Documents, as we say in NoSQL speak).

dash

When we navigate to the Orders collection, we can see that the data has been imported correctly. We can also see the CustomerID column that refers to a column in the Customer collection.

orders

The next step is to start the mapping of the relations.

Mapping of Relations Between Collections

In order to create relations, we must change the schema of our database. First, we switch to Developer mode (button in the upper right corner) and then navigate to Orders > Settings.

The screen shot below shows all the fields on the Orders collection. We then select the CustomerID field, and change it from a textdata type to a Lookup to Customers. Note that we also need to select the Advanced option and then pick the foreign key field from the Customers collection (CustomerID).

mapping

The mapping process described here is repeated for all the relations we wish to map.

For example, to create a relation between Orders and Order-details, we navigate to the Order-detail collection and change the OrderIDfield to a Lookupthat refers to Orders with the foreign key OrderID.

The screenshot below shows the Order-detail view with the finished mappings against both Orders and Customers.

orders-finished-mapping

As we now have a data schema that "knows" about the relations between our collections, restdb.io provides us with some really useful productivity features.

Navigate to any Product shows all Order-details for that particular product.

product-detail

And if you click on the Order-Details tab, you will see all associated records. The same "automagic" navigation tools are provided for all the relations in our data model.

product-order-details

The REST API

What does the Northwind data look like in our NoSQL database?

Let's run a cURL command line query to get a particular Order.

curl -k -i -H "Content-Type: application/json"\
-H "x-apikey: <some key>"\
-X GET 'https://northwindnosql-39ba.restdb.io/rest/orders/594a3c65f8b84a36000016be'

We get back the following JSON document.

{
  "_id": "594a3c65f8b84a36000016be",
  "OrderID": 10249,
  "CustomerID": [
    {
      "_id": "594a3d22f8b84a36000022ca",
      "CustomerID": "TOMSP",
      "CompanyName": "Toms Spezialitäten",
      "ContactName": "Karin Josephs",
      "ContactTitle": "Marketing Manager",
      "Address": "Luisenstr. 48",
      "City": "Münster",
      "Region": "NULL",
      "PostalCode": 44087,
      "Country": "Germany",
      "Phone": "0251-031259",
      "Fax": "0251-035695",
      "_created": "2017-06-21T09:32:18.575Z"
    }
  ],
  "EmployeeID": [
    {
      "_id": "594a3d88f8b84a36000022f2",
      "EmployeeID": "6",
      "LastName": "Suyama",
      "FirstName": "Michael",
      "Title": "Sales Representative",
      "TitleOfCourtesy": "Mr.",
      "BirthDate": "1963-07-02T00:00:00.000Z",
      "HireDate": "1993-10-17T00:00:00.000Z",
      "Address": "Coventry House",
      "_created": "2017-06-21T09:34:00.201Z"
    }
  ],
  "OrderDate": "1996-07-05T00:00:00.000Z",
  "RequiredDate": "1996-08-16T00:00:00.000Z",
  "ShippedDate": "1996-07-10T00:00:00.000Z",
  "ShipVia": 1,
  "Freight": 11.61,
  "ShipName": "Toms Spezialitäten",
  "ShipAddress": "Luisenstr. 48",
  "ShipCity": "Münster",
  "ShipRegion": "NULL",
  "ShipPostalCode": "44087",
  "ShipCountry": "Germany"
}

We see that the fields CustomerID and EmployeeID which used to be just text, has been replaced with the actual documents (records) they refer.

This differs from SQL databases, where we would have to join the three collections to produce a similar result.

In the NoSQL world, we embed and duplicate — and that's okay.

Conclusion

SQL and NoSQL databases will probably continue to live side by side in a long time ahead. Due to the increasing popularity of document databases like MongoDB, it's important to understand how you can migrate from one model to another. This blog post shows that this is actually quite easy.

Database Relational database NoSQL

Published at DZone with permission of Jon Erik Solheim, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • GPT-3 Playground: The AI That Can Write for You
  • Problems of Cloud Cost Management: A Socio-Technical Analysis
  • DevSecOps Benefits and Challenges
  • Implementing Infinite Scroll in jOOQ

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: