Skip to content

DOC-3770 #2799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions content/sdk/development-intro.dita
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<section>
<title>Using Couchbase</title>
<p>Once you've <xref href="../install/install-intro.dita#topic_edn_wtd_54">installed the
server</xref>, you can start storing, retrieving, and querying documents with
server</xref>, and <xref href="../clustersetup/create-bucket.dita">created
a test bucket</xref>, you can start storing, retrieving, and querying documents with
Couchbase. You can start with an SDK, the command-line cbc tool, or the web
browser.</p>
<p>Every item in a database goes through the basic <i>CRUD</i> cycle, which is typical
Expand All @@ -40,84 +41,84 @@
the command line client, don’t worry - we’ll walk through the steps in the next
chapter.</p>
</section>
<section><title>Creating documents</title><p>Create the document <i>mnunberg.json</i>. It
<section><title>Creating documents</title><p>Create the document <i>josmith.json</i>. It
can be anywhere on your file
system:</p><codeblock outputclass="language-json">{
"name": "Mark Nunberg",
"email": "mark.nunberg@couchbase.com",
"name": "Jo Smith",
"email": "jo.smith@example.com",
"privs": ["admin"],
"location": {
"country": "United States",
"state": "NV",
"city": "Reno"
},
"following": [
"u:tgreenstein", "u:ingenthr", "u:potus"
"u:asmith", "u:bsmith", "u:potus"
],
"likes": ["doge", "pastries"]
"likes": ["dogs", "pastries"]
}</codeblock><p>Now,
insert the document into Couchbase using the <i><codeph>cbc</codeph></i>
utility:</p><screen>$ <b>cbc create -u <varname>username</varname> -P <varname>password</varname> -U couchbase://<varname>hostname-or-ip</varname>/default --mode insert mnunberg &lt; mnunberg.json</b></screen><codeph>mnunberg</codeph>
utility:</p><screen>$ <b>cbc create -u <varname>username</varname> -P <varname>password</varname> -U couchbase://<varname>hostname-or-ip</varname>/myTestBucket --mode insert josmith &lt; josmith.json</b></screen><codeph>josmith</codeph>
is the document’s ID, which is redirected (<codeph>&lt;</codeph>) to the
<cmdname>cbc</cmdname> command’s standard input.</section>
<cmdname>cbc</cmdname> command’s standard input.</section>
<section>
<title>Reading documents by ID</title>
<p>Documents can be retrieved using their IDs. Retrieving a document by ID is extremely
fast. The following query takes about 1 millisecond.</p>
<screen>$ <b>cbc cat -u <varname>username</varname> -P <varname>password</varname> -U couchbase://<varname>hostname-or-ip</varname>/mnunberg</b>
<screen>$ <b>cbc cat -u <varname>username</varname> -P <varname>password</varname> -U couchbase://<varname>hostname-or-ip</varname>/josmith</b>
{
"name": "Mark Nunberg",
"email": "mark.nunberg@couchbase.com",
"name": "Jo Smith",
"email": "jo.smith@example.com",
"privs": ["admin"],
"location": {
"country": "United States",
"state": "NV",
"city": "Reno"
},
"following": [
"u:tgreenstein", "u:ingenthr", "u:potus"
"u:asmith", "u:bsmith", "u:potus"
],
"likes": ["doge", "pastries"]
"likes": ["dogs", "pastries"]
}</screen>
</section>
<section>
<title>Reading documents by querying</title>
<p>Retrieving a document may be done using a unique identifier assigned by the
application at the document’s creation, or by inspecting its contents to see if it
matches a certain criteria. ID lookups are quicker, but querying documents allows
matches a certain criterion. ID lookups are quicker, but querying documents allows
for richer search capabilities (for example, "Give me all likes and followed users
located in the US?" versus "Give me a user with the ID e3d882a4").</p>
located in the US" versus "Give me a user with the ID e3d882a4").</p>
<screen>$ <b>cbc n1ql \</b>
<b>'SELECT following, likes FROM default WHERE location.country = "United States"'</b>
{
"following": [
"u:tgreenstein",
"u:ingenthr",
"u:asmith",
"u:bsmith",
"u:potus"
],
"likes": [
"doge",
"dogs",
"pastries"
]
</screen>
</section>
<section><title>Updating documents</title><p>Updating a document means changing the existing
document. For example, take the file above and edit the <codeph>likes</codeph>
field:</p><screen> ...
"likes": ["doge", "pastries", <b>"couchbase"</b>]
"likes": ["dogs", "pastries", <b>"couchbase"</b>]
....</screen>Then
use the <cmdname>cbc</cmdname> tool to update the document in
Couchbase:<screen>$ <b>cbc create --mode replace mnunberg &lt; mnunberg.json</b></screen></section>
Couchbase:<screen>$ <b>cbc create --mode replace josmith &lt; josmith.json</b></screen></section>
<section>
<title>Deleting documents</title>
<p>This example shows how to delete the document with the ID
<codeph>mnunberg</codeph>.</p>
<screen>$ <b>cbc rm mnunberg</b></screen>
<codeph>josmith</codeph>.</p>
<screen>$ <b>cbc rm josmith</b></screen>
</section>
<section>
<title>Couchbase clients</title>
<p>Clients access data by connecting to a Couchbase cluster over the network. The most
common type of client is a Couchbase SDK which is a full programmatic API that
common type of client is a Couchbase SDK, which is a full programmatic API that
enables applications to take the best advantage of Couchbase. The command line
client provides a quick and streamlined interface for simple access and is suitable
if you just want to access an item without writing any code.</p>
Expand Down