Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Many NoSQL databases store data without a predefined schema, and CouchDB is no exception. In this video, we'll start up CouchDB and start storing some data. First, go to your Applications folder, and navigate to CouchDB. When you double-click on CouchDB, it automatically opens up the Futon interface. We already have a couple of databases in this fresh server. We have _replicator and _users. These two databases are used to help run CouchDB.
CouchDB uses these databases as a way of organizing documents in specific sets. Databases are also used to enforce security and access control across all of the documents that are part of that database. In this course, we'll be creating a website for a restaurant. So let's create a database to support that. Click the Create Database link and then give the database a name of restaurant. Then click Create.
Now, we have a fresh database with no documents in it. Let's create the first document by clicking New Document. You'll notice that it automatically gave us a hash for the ID field. Under normal circumstances, you'll want to accept this hash value unless you have a good reason not to use it. Now, let's start filling in this document. I'm going to go to the exercise files, and then open content.txt. So, let's create a welcome document now.
I'm copying Welcome, and now I'm going to click Add Field. I'm going to give this field a name of name, and the value is going to be Welcome. I now also want to create another field for the content. Let's copy The Corner Cafe, and now click Add Field again, and give this field the name of content, and then paste in The Corner Cafe. Once these values are in the document, click the green check next to each value.
Now, finally click Save Document. You'll notice that the _rev field got added. This keeps track of the revision number. Each time we make a change to this document, this revision number is going to increment. Let's create another document in this database. Click on restaurant, and click on New Document. We're going to call this document Hours. So click Add Field and then type in name, add another field and call it content.
And now copy in the hours. Click the green check next to each field, and then click Save Document. Now I'm going to add one more field. I'm going to call this author. Then, I'm going to add my name here. Click the green check, and then click Save Document. Now, let's click restaurant, and then open these two documents in new tabs. You'll notice that we have this content here for The Corner Cafe and the name is Welcome, while we have author here as another field in addition to content and name.
Even though these two documents are in the same database, they have different field sets. And this is okay because that's something that CouchDB allows. Storing data in CouchDB is as easy as naming a database and naming field-value pairs. The structure does not have to be the same from document to document. You can add the exact fields you want for each one.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101561 Viewers
61 Video lessons · 88320 Viewers
71 Video lessons · 72184 Viewers
56 Video lessons · 103939 Viewers
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.
Your file was successfully uploaded.