Skip to content

Commit 6c701de

Browse files
DA-1354: Fix typos and improve clarity in C++ quickstart tutorial (#92)
* DA-1354: Fix typos and improve clarity in C++ quickstart tutorial * DA-1354 update: tutorial/markdown/c++/cxx-quickstart.md Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * DA-1354 update: tutorial/markdown/c++/cxx-quickstart.md Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * DA-1354 update: tutorial/markdown/c++/cxx-quickstart.md Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 959e0fe commit 6c701de

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

tutorial/markdown/c++/cxx-quickstart.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ path: "/tutorial-cxx-quickstart"
44
title: Quickstart in Couchbase with C++
55
short_title: C++ Quickstart
66
description:
7-
- Learn to to use Couchbase C++ SDK to interact with the database.
7+
- Learn to use the Couchbase C++ SDK to interact with the database.
88
- See how you can fetch data from Couchbase using SQL++ queries
99
- Explore how you can perform search operations using Search indexes.
1010
- Explore CRUD operations in action with Couchbase
@@ -23,10 +23,9 @@ sdk_language:
2323
length: 30 Mins
2424
---
2525

26-
<!-- [abstract] -->
27-
# Quickstart in Couchbase with C++
26+
## Introduction
2827

29-
In this tutorial, you will learn how to connect to a Couchbase Capella cluster to create, read, update, and delete documents, how to write simple parametrized SQL++ queries and how to create, and perform simple and complex text search using Search indexes.
28+
In this tutorial, you will learn how to connect to a Couchbase Capella cluster to create, read, update, and delete documents, how to write simple parameterized SQL++ queries, and how to create and perform simple and complex search operations using Search indexes.
3029

3130
## Prerequisites
3231

@@ -61,7 +60,7 @@ Specifically, you need to do the following:
6160
- Create the [database credentials](https://docs.couchbase.com/cloud/clusters/manage-database-users.html) to access the travel-sample bucket (Read and Write) used in the application.
6261
- [Allow access](https://docs.couchbase.com/cloud/clusters/allow-ip-address.html) to the Cluster from the IP on which the application is running.
6362

64-
All configuration for communication with the database is read from the environment variables. We have provided a convenience feature in this quickstart to setup the required environment variables using a shell script `setup_env_vars.sh`. Change the values of the following lines:
63+
All configuration for communication with the database is read from the environment variables. We have provided a convenience feature in this quickstart to setup the required environment variables using a shell script `set_env_vars.sh`. Change the values of the following lines:
6564

6665
```sh
6766
export DB_CONN_STR=<connection_string>
@@ -75,13 +74,13 @@ export COL_NAME=<collection_name>
7574
7675
Run the command:
7776
```sh
78-
source setup_env_vars.sh
77+
source set_env_vars.sh
7978
```
8079
This will set the environment variables for that session.
8180

8281
### Install Dependencies and Building
8382

84-
This project makes use of CMake and CPM to install dependencies.
83+
This project makes use of CMake and CPM to install dependencies.
8584

8685

8786
```sh
@@ -91,7 +90,7 @@ cmake ..
9190
cmake --build .
9291
```
9392

94-
This will download and install all the dependencies required for the project to built. Along with that it will build the executable required to run the application.
93+
This will download and install all the dependencies required for the project to be built. Along with that it will build the executable required to run the application.
9594

9695
## Running The Application
9796

@@ -127,12 +126,12 @@ This quickstart utilizes two collections: **airline** and **hotel**. The **airli
127126

128127
## Code Review
129128

130-
To begin this tutorial, clone the repo and open it up in the IDE of your choice. Now you can explore about how to interact with Couchbase Server using the C++ SDK.
129+
To begin this tutorial, clone the repo and open it up in the IDE of your choice. Now you can explore how to interact with Couchbase Server using the C++ SDK.
131130

132-
We have separated out the SDK code and the main function. The `db.h` and `db.cpp` contain the declaration and the implementation of utility functions we will use to parse environment variables and create a connection to the cluster. `operations.h` and `operations.cpp` contain all the functions that perform operations on the db. Both `db.cpp` and `operations.cpp` are combined to make a static library. The tests are similarly separated out in the `tests` folder which utilise the library created earlier. The `main.cpp` is the executable which is also built by linking the library and contains code that demonstrates the usage of the functions we defined earlier to initeract with the db.
131+
We have separated out the SDK code and the main function. The `db.h` and `db.cpp` contain the declaration and the implementation of utility functions we will use to parse environment variables and create a connection to the cluster. `operations.h` and `operations.cpp` contain all the functions that perform operations on the database. Both `db.cpp` and `operations.cpp` are combined to make a static library. The tests are similarly separated out in the `tests` folder which utilize the library created earlier. The `main.cpp` is the executable which is also built by linking the library and contains code that demonstrates the usage of the functions we defined earlier to interact with the database.
133132

134133
### Connecting to the Cluster
135-
In `db.h`, we include the required header files to work with C++ SDK in order to for implement the functions required to initialize the DB. In the `db.cpp` we implement the functions that help us connect to the db. We begin by implementing few utility functions that will help us later. The `parseEnvironmentVariables` serves as a utility to get the values set for a list of environment variables. This enables us to get the connection parameters and credentials, set by running `source set_env_vars.sh`. Following this `checkScopeAndColExists` and `checkSearchEnabled` are implemented, used to check for existence of scope and collection of given name and to check if search service enabled respectively. Finally we have the InitCluster function which returns the connection objects as a tuple.
134+
In `db.h`, we include the required header files to work with C++ SDK in order to implement the functions required to initialize the database. In the `db.cpp` we implement the functions that help us connect to the database. We begin by implementing a few utility functions that will help us later. The `parseEnvironmentVariables` serves as a utility to get the values set for a list of environment variables. This enables us to get the connection parameters and credentials set by running `source set_env_vars.sh`. Following this, `checkScopeAndColExists` and `checkSearchEnabled` are implemented to check for the existence of a scope and collection of a given name and to verify if the search service is enabled respectively. Finally we have the InitCluster function which returns the connection objects as a tuple.
136135

137136
```c++
138137
// db.h
@@ -164,7 +163,7 @@ return {cluster, bucket, scope, col};
164163

165164

166165
## Operations
167-
Operations for interacting with the db is defined and implemented in `operations.h` and `operations.cpp`
166+
Operations for interacting with the database are defined and implemented in `operations.h` and `operations.cpp`.
168167
### Insert Document
169168
Insert function is the equivalent of the POST request and can be used to insert new documents to the collection. We can pass the document to be inserted as a JSON string or as a JSON file path, the function takes in file_flag which is used to differentiate between the two.
170169
- The value gets converted to the type `tao::json::value` and inserts it to the collection if `file_flag=false`
@@ -196,7 +195,7 @@ auto upsert_res2 = Upsert(col, "quickstart_test2", "doc.json", true);
196195
```
197196

198197
### Read
199-
Read function is equivalent to GET requests and can be used fetch documents using the `doc_id`.
198+
Read function is equivalent to GET requests and can be used to fetch documents using the `doc_id`.
200199
- First checks if the document exists using `col.exists(doc_id)`.
201200
- If the document exists, it retrieves the document's content using `col.get(doc_id)` and returns it after converting it to `tao::json::value` for easier usage on return.
202201
- If an error occurs (e.g., document not found), it prints an error message and returns an empty tao::json::value object.
@@ -231,7 +230,7 @@ auto res = Delete(col, doc_id);
231230
We can use the `Query` function to execute any N1QL (SQL++) query on a scope.
232231
- Executes the N1QL query using the provided `scope.query(query, opts)`.
233232
- Returns the result of the query if successful. The result is added to a `std::vector<std::string>` object that contains the `id, country, avg_rating, title`.
234-
- We can pass `opts` parameter, which can be used to insert positonal parameters in the query.
233+
- We can pass `opts` parameter, which can be used to insert positional parameters in the query.
235234
- If there is an error, it prints an error message and returns an empty result object.
236235

237236
```c++
@@ -272,7 +271,7 @@ std::string index_name = CreateSearchIndex(scope, "hotel_search_index.json");
272271
```
273272

274273
### Search By Name
275-
The `SearchByName` function aims to demonstrates the usage of a search index to search for documents in a scope.
274+
The `SearchByName` function aims to demonstrate the usage of a search index to search for documents in a scope.
276275
Params:
277276
- `scope`: The Couchbase scope to search in.
278277
- `index`: The search index name to use for the query.
@@ -297,7 +296,7 @@ std::cout << "Search result contains:\t" << search_res.size() << std::endl;
297296
```
298297

299298
### Filter
300-
The `Filter` function aims to demo the construction and execution of a `conjuction_query` which can be described as an `AND` operation on two or more types of filters. This particular implementation performs a conjunction on `couchbase::match_query("United States").field("country")` and `couchbase::term_query("San Diego").field("city")`.
299+
The `Filter` function aims to demo the construction and execution of a `conjunction_query` which can be described as an `AND` operation on two or more types of filters. This particular implementation performs a conjunction on `couchbase::match_query("United States").field("country")` and `couchbase::term_query("San Diego").field("city")`.
301300

302301
```c++
303302
//operations.cpp

0 commit comments

Comments
 (0)