Viewers: in countries Watching now:
Flat fields are just one of the many options you have for storing data in CouchDB. Arrays and objects allow you to nest data within documents. Right now, we have the Futon interface loaded with the restaurant database in place. So let's navigate to restaurant. We already have a couple of documents ready to go. Click on the one with the second revision. Here we have the document with the hours. Let's say we want to add the hours as an object where we can more readily access that data in a structured format.
Let's go to the exercise files to paste that in. Copy this object, and then create a new field for it by clicking Add Field. I'm going to call this field Hours, and now I am going to paste that data into this field, and then click the green check. You'll notice now we have each day of the week bolded, and the value is in quotes.
If we click over to the source, you'll see that hours is structured within this document. One thing that's very important to remember is that the JSON format is very strictly adhered to. If we edit this field and change to single quotes, the field is then just interpreted as plain text. Then we lose the structure of this field.
When we change it back to proper JSON, the structure returns. Let's click on Save Document, and then add a new document. Navigate to restaurant and click New Document. We're now going to create a document about the delivery options. Copy the word Delivery, and then click Add Field, and then add the name name as a field. Paste in Delivery, and then click Add Field again, and now copy the content.
Name this field content and now paste in the content. Finally, we're going to add the phone numbers as an array. This business has two phone lines. We're only advertising the one phone line for the moment, but at some point in the future, we might have an application that uses both. So copy the array, click Add Field, and then type numbers as the field name.
Then paste in the array. Finally, check off all four fields. You'll notice that we used proper JSON and the field was interpreted as an array. Now that we have all the data entered into this document, be sure to save it. JSON makes it possible for you to nest data in CouchDB as well as other NoSQL databases. Just make sure the syntax is correct, so that your data is recognized as JSON.
There are currently no FAQs about Up and Running with NoSQL Databases.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.