CouchDB and PHP Web Development Beginner’s Guide
上QQ阅读APP看书,第一时间看更新

Time for action — creating a document in Futon

We've gone through the updating of existing documents. Let's create a document from scratch in Futon.

  1. Go to the database overview by clicking on the database name, test-db, in the header.
  2. Click on New Document.
  3. A blank document is created and ready for us to put in new fields. Notice that the _id is already set for us (but we can change it if we want).
  4. Click on Add Field to create a new field, and call it location.
  5. Double-click on the value right next to the label that says null, and enter in your current location.
  6. Click on Add Field to create a new field, and call it name.
  7. Double-click on the value right next to the label that says null, and enter in your name.
  8. Click on Save Document at the top of the page.
  9. The document has been saved. Notice that it now has a _rev value set.

What just happened?

You just used Futon to create a document from scratch. When the document was first created, CouchDB created a unique ID for you to set it as the value of the _id field. Next, you added the name field and inputted your name as its value. Finally, you saved it to create a new document. We've talked about how documents can have completely different fields, but this is the first time we've actually done it!