Skip to content

Commit 5a67640

Browse files
authored
Merge pull request #3 from SnehaGunda/PrivateLink1
Addressing PR reviewer feedback
2 parents 90e4b8a + e274d1c commit 5a67640

File tree

1 file changed

+138
-134
lines changed

1 file changed

+138
-134
lines changed

articles/cosmos-db/couchbase-cosmos-migration.md

Lines changed: 138 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ The following are the key features that work differently in Azure Cosmos DB when
2424

2525
## Key differences
2626

27-
1. Azure Cosmos DB has an "ID" field within the document whereas Couchbase has the id as a part of bucket. The "id" field is unique across the partition.
27+
* Azure Cosmos DB has an "ID" field within the document whereas Couchbase has the ID as a part of bucket. The "ID" field is unique across the partition.
2828

29-
2. Azure Cosmos DB scales by using the partitioning or sharding technique. Which means it splits the data into multiple shards/partitions. These partitions/shards are created based on the partition key property that you provide. You can select the partition key to optimize read as well write operations or read/write optimized too. To learn more, see the [partitioning](./partition-data.md) article.
29+
* Azure Cosmos DB scales by using the partitioning or sharding technique. Which means it splits the data into multiple shards/partitions. These partitions/shards are created based on the partition key property that you provide. You can select the partition key to optimize read as well write operations or read/write optimized too. To learn more, see the [partitioning](./partition-data.md) article.
3030

31-
3. In Azure Cosmos DB, it is not required for the top-level hierarchy to denote the collection because the collection name already exists. This feature makes the JSON structure much simpler. The following is an example that shows differences in the data model between Couchbase and Azure Cosmos DB:
31+
* In Azure Cosmos DB, it is not required for the top-level hierarchy to denote the collection because the collection name already exists. This feature makes the JSON structure much simpler. The following is an example that shows differences in the data model between Couchbase and Azure Cosmos DB:
3232

33-
**Couchbase**: Document Id = "99FF4444"
33+
**Couchbase**: Document ID = "99FF4444"
3434

3535
```json
3636
{
@@ -60,7 +60,7 @@ The following are the key features that work differently in Azure Cosmos DB when
6060
}
6161
```
6262

63-
**Azure Cosmos DB**: Refer "id" within the document as shown below
63+
**Azure Cosmos DB**: Refer "ID" within the document as shown below
6464

6565
```json
6666
{
@@ -94,76 +94,80 @@ The following are the key features that work differently in Azure Cosmos DB when
9494

9595
Azure Cosmos DB has following SDKs to support different Java frameworks:
9696

97-
1. Async SDK
98-
2. Spring Boot SDK
97+
* Async SDK
98+
* Spring Boot SDK
9999

100100
The following sections describe when to use each of these SDKs. Consider an example where we have three types of workloads:
101101

102102
## Couchbase as document repository & spring data-based custom queries
103103

104104
If the workload that you are migrating is based on Spring Boot Based SDK, then you can use the following steps:
105105

106-
**Step-1:** Add parent to the POM.xml file:
106+
1. Add parent to the POM.xml file:
107107

108-
```java
109-
<parent>
110-
<groupId>org.springframework.boot</groupId>
111-
<artifactId>spring-boot-starter-parent</artifactId>
112-
<version>2.1.5.RELEASE</version>
113-
<relativePath/>
114-
</parent>
115-
```
108+
```java
109+
<parent>
110+
<groupId>org.springframework.boot</groupId>
111+
<artifactId>spring-boot-starter-parent</artifactId>
112+
<version>2.1.5.RELEASE</version>
113+
<relativePath/>
114+
</parent>
115+
```
116116

117-
**Step-1a:** Add properties to the POM.xml file:
117+
1. Add properties to the POM.xml file:
118118

119-
```java
120-
<azure.version>2.1.6</azure.version>
121-
Step-1b: Add Dependency in the POM:
122-
<dependency>
123-
<groupId>com.microsoft.azure</groupId>
124-
<artifactId>azure-cosmosdb-spring-boot-starter</artifactId>
125-
<version>2.1.6</version>
126-
</dependency>
127-
```
119+
```java
120+
<azure.version>2.1.6</azure.version>
121+
```
128122

129-
**Step-2:** Add application properties under resources and specify the following. Make sure to replace the URL, key, and database name parameters:
123+
1. Add dependencies to the POM.xml file:
130124

131-
```java
132-
azure.cosmosdb.uri=<your-cosmosDB-URL>
133-
azure.cosmosdb.key=<your-cosmosDB-key>
134-
azure.cosmosdb.database=<your-cosmosDB-dbName>
135-
```
125+
```java
126+
<dependency>
127+
<groupId>com.microsoft.azure</groupId>
128+
<artifactId>azure-cosmosdb-spring-boot-starter</artifactId>
129+
<version>2.1.6</version>
130+
</dependency>
131+
```
136132

137-
**Step-3:** Define the name of the collection in the model. You can also specify further annotations, for example, id, partition key to denote them explicitly:
133+
1. Add application properties under resources and specify the following. Make sure to replace the URL, key, and database name parameters:
138134

139-
```java
140-
@Document(collection = "mycollection")
141-
public class User {
142-
@id
143-
private String id;
144-
private String firstName;
145-
@PartitionKey
146-
private String lastName;
147-
}
148-
```
135+
```java
136+
azure.cosmosdb.uri=<your-cosmosDB-URL>
137+
azure.cosmosdb.key=<your-cosmosDB-key>
138+
azure.cosmosdb.database=<your-cosmosDB-dbName>
139+
```
140+
141+
1. Define the name of the collection in the model. You can also specify further annotations. For example, ID, partition key to denote them explicitly:
142+
143+
```java
144+
@Document(collection = "mycollection")
145+
public class User {
146+
@id
147+
private String id;
148+
private String firstName;
149+
@PartitionKey
150+
private String lastName;
151+
}
152+
```
149153

150154
The following are the code snippets for CRUD operations:
151155

152156
### Insert and update operations
153157

154-
Where *_repo* is the object of repository and *doc* is the POJO class’s object. You can use `.save` to insert or upsert (if document with specified id found). The following code snippet shows how to insert or update a doc object:
158+
Where *_repo* is the object of repository and *doc* is the POJO class’s object. You can use `.save` to insert or upsert (if document with specified ID found). The following code snippet shows how to insert or update a doc object:
155159

156160
```_repo.save(doc);```
157161

158162
### Delete Operation
159163

160-
Consider the following code snippet, where doc object will have Id and partition key mandatory to locate and delete the object:
164+
Consider the following code snippet, where doc object will have ID and partition key mandatory to locate and delete the object:
161165

162166
```_repo.delete(doc);```
163167

164168
### Read Operation
165169

166-
You can read the document with or without specifying the partition key. If you don’t specify the partition key, then it is treated as a cross-partition query. Consider the following code samples, first one will perform operation using id and partition key field. Second example uses a regular field & without specifying the partition key field.
170+
You can read the document with or without specifying the partition key. If you don’t specify the partition key, then it is treated as a cross-partition query. Consider the following code samples, first one will perform operation using ID and partition key field. Second example uses a regular field & without specifying the partition key field.
167171

168172
* ```_repo.findByIdAndName(objDoc.getId(),objDoc.getName());```
169173
* ```_repo.findAllByStatus(objDoc.getStatus());```
@@ -180,52 +184,52 @@ N1QL queries is the way to define queries in the Couchbase.
180184

181185
You can notice the following changes in your N1QL queries:
182186

183-
1. You don’t need to use the META keyword or refer to the first-level document. Instead you can create your own reference to the container. In this example, we have considered it as "c" (it can be anything). This reference is used as a prefix for all the first-level fields. Fr example, c.id, c.country etc.
187+
* You don’t need to use the META keyword or refer to the first-level document. Instead you can create your own reference to the container. In this example, we have considered it as "c" (it can be anything). This reference is used as a prefix for all the first-level fields. Fr example, c.id, c.country etc.
184188

185-
2. Instead of "ANY" now you can do a join on subdocument and refer it with a dedicated alias such as "m". Once you have created alias for a subdocument you need to use alias. For example, m.Country.
189+
* Instead of "ANY" now you can do a join on subdocument and refer it with a dedicated alias such as "m". Once you have created alias for a subdocument you need to use alias. For example, m.Country.
186190

187-
3. The sequence of OFFSET is different in Azure Cosmos DB query, first you need to specify OFFSET then LIMIT.
191+
* The sequence of OFFSET is different in Azure Cosmos DB query, first you need to specify OFFSET then LIMIT.
188192
It is recommended not to use Spring Data SDK if you are using maximum custom defined queries as it can have unnecessary overhead at the client side while passing the query to Azure Cosmos DB. Instead we have a direct Async Java SDK, which can be utilized much efficiently in this case.
189193

190194
### Read operation
191195

192196
Use the Async Java SDK with the following steps:
193197

194-
**Step-1:** Configure the following dependency onto the POM.xml file:
198+
1. Configure the following dependency onto the POM.xml file:
195199

196-
```java
197-
<!-- https://mvnrepository.com/artifact/com.microsoft.azure/azure-cosmosdb -->
198-
<dependency>
199-
<groupId>com.microsoft.azure</groupId>
200-
<artifactId>azure-cosmos</artifactId>
201-
<version>3.0.0</version>
202-
</dependency>
203-
```
200+
```java
201+
<!-- https://mvnrepository.com/artifact/com.microsoft.azure/azure-cosmosdb -->
202+
<dependency>
203+
<groupId>com.microsoft.azure</groupId>
204+
<artifactId>azure-cosmos</artifactId>
205+
<version>3.0.0</version>
206+
</dependency>
207+
```
204208

205-
**Step-2:** Create a connection object for Azure Cosmos DB by using the `ConnectionBuilder` method as shown in the following example. Make sure you put this declaration into the bean such that the following code should get executed only once:
209+
1. Create a connection object for Azure Cosmos DB by using the `ConnectionBuilder` method as shown in the following example. Make sure you put this declaration into the bean such that the following code should get executed only once:
206210

207-
```java
208-
ConnectionPolicy cp=new ConnectionPolicy();
209-
cp.connectionMode(ConnectionMode.DIRECT);
210-
211-
if(client==null)
212-
client= CosmosClient.builder()
213-
.endpoint(Host)//(Host, MasterKey, dbName, collName).Builder()
214-
.connectionPolicy(cp)
215-
.key(MasterKey)
216-
.consistencyLevel(ConsistencyLevel.EVENTUAL)
217-
.build();
218-
219-
container = client.getDatabase(_dbName).getContainer(_collName);
220-
```
211+
```java
212+
ConnectionPolicy cp=new ConnectionPolicy();
213+
cp.connectionMode(ConnectionMode.DIRECT);
214+
215+
if(client==null)
216+
client= CosmosClient.builder()
217+
.endpoint(Host)//(Host, MasterKey, dbName, collName).Builder()
218+
.connectionPolicy(cp)
219+
.key(MasterKey)
220+
.consistencyLevel(ConsistencyLevel.EVENTUAL)
221+
.build();
222+
223+
container = client.getDatabase(_dbName).getContainer(_collName);
224+
```
221225

222-
**Step-3:** To execute the query, you need to run the following code snippet:
226+
1. To execute the query, you need to run the following code snippet:
223227

224-
```java
225-
Flux<FeedResponse<CosmosItemProperties>> objFlux= container.queryItems(query, fo);
226-
```
228+
```java
229+
Flux<FeedResponse<CosmosItemProperties>> objFlux= container.queryItems(query, fo);
230+
```
227231

228-
Now, with the help of above method you can pass multiple queries and execute without any hassle. In case you have the requirement to execute one large query, which can be split into multiple queries then try the following code snippet instead of the above one:
232+
Now, with the help of above method you can pass multiple queries and execute without any hassle. In case you have the requirement to execute one large query, which can be split into multiple queries then try the following code snippet instead of the previous one:
229233

230234
```java
231235
for(SqlQuerySpec query:queries)
@@ -299,70 +303,70 @@ Then subscribe to mono, refer mono subscription snippet in insert operation. The
299303

300304
This is a simple type of workload in which you can perform lookups instead of queries. Use the following steps for key/value pairs:
301305

302-
**Step-1:** Consider having "/id" as primary key, which will makes sure you can perform lookup operation directly in the specific partition. Create a collection and specify "/id" as partition key.
306+
1. Consider having "/ID" as primary key, which will makes sure you can perform lookup operation directly in the specific partition. Create a collection and specify "/ID" as partition key.
303307

304-
**Step-2:** Switch off the indexing completely. Because you will execute lookup operations, there is no point of carrying indexing overhead. To turn off indexing, sign into Azure Portal, goto Azure Cosmos DB Account. Open the **Data Explorer**, select your **Database** and the **Container**. Open the **Scale & Settings** tab and select the **Indexing Policy**. Currently indexing policy looks like the following:
305-
306-
```json
307-
{
308-
"indexingMode": "consistent",
309-
"includedPaths":
310-
[
311-
{
308+
1. Switch off the indexing completely. Because you will execute lookup operations, there is no point of carrying indexing overhead. To turn off indexing, sign into Azure portal, goto Azure Cosmos DB Account. Open the **Data Explorer**, select your **Database** and the **Container**. Open the **Scale & Settings** tab and select the **Indexing Policy**. Currently indexing policy looks like the following:
309+
310+
```json
311+
{
312+
"indexingMode": "consistent",
313+
"includedPaths":
314+
[
315+
{
312316
"path": "/*",
313317
"indexes":
314-
[
318+
[
315319
{
316-
"kind": "Range",
317-
"dataType": "Number"
320+
"kind": "Range",
321+
"dataType": "Number"
318322
},
319323
{
320-
"kind": "Range",
321-
"dataType": "String"
324+
"kind": "Range",
325+
"dataType": "String"
322326
},
323327
{
324-
"kind": "Spatial",
325-
"dataType": "Point"
328+
"kind": "Spatial",
329+
"dataType": "Point"
326330
}
327-
]
328-
}
329-
],
330-
"excludedPaths":
331-
[
332-
{
333-
"path": "/path/to/single/excluded/property/?"
334-
},
335-
{
336-
"path": "/path/to/root/of/multiple/excluded/properties/*"
337-
}
338-
]
339-
}
340-
````
341-
342-
Replace the above indexing policy with the following policy:
343-
344-
```json
345-
{
346-
"indexingMode": "none"
347-
}
348-
```
349-
350-
**Step-3:** Use the following code snippet to create the connection object. Connection Object (to be placed in @Bean or make it static):
331+
]
332+
}
333+
],
334+
"excludedPaths":
335+
[
336+
{
337+
"path": "/path/to/single/excluded/property/?"
338+
},
339+
{
340+
"path": "/path/to/root/of/multiple/excluded/properties/*"
341+
}
342+
]
343+
}
344+
````
345+
346+
Replace the above indexing policy with the following policy:
347+
348+
```json
349+
{
350+
"indexingMode": "none"
351+
}
352+
```
351353

352-
```java
353-
ConnectionPolicy cp=new ConnectionPolicy();
354-
cp.connectionMode(ConnectionMode.DIRECT);
355-
356-
if(client==null)
357-
client= CosmosClient.builder()
358-
.endpoint(Host)//(Host, MasterKey, dbName, collName).Builder()
359-
.connectionPolicy(cp)
360-
.key(MasterKey)
361-
.consistencyLevel(ConsistencyLevel.EVENTUAL)
362-
.build();
363-
364-
container = client.getDatabase(_dbName).getContainer(_collName);
365-
```
354+
1. Use the following code snippet to create the connection object. Connection Object (to be placed in @Bean or make it static):
355+
356+
```java
357+
ConnectionPolicy cp=new ConnectionPolicy();
358+
cp.connectionMode(ConnectionMode.DIRECT);
359+
360+
if(client==null)
361+
client= CosmosClient.builder()
362+
.endpoint(Host)//(Host, MasterKey, dbName, collName).Builder()
363+
.connectionPolicy(cp)
364+
.key(MasterKey)
365+
.consistencyLevel(ConsistencyLevel.EVENTUAL)
366+
.build();
367+
368+
container = client.getDatabase(_dbName).getContainer(_collName);
369+
```
366370

367371
Now you can execute the CRUD operations as follows:
368372

@@ -437,9 +441,9 @@ Then subscribe to mono, refer mono subscription snippet in insert operation. The
437441

438442
There are two ways to migrate data.
439443

440-
1. **Use Azure Data Factory:** This is the most recommended method to migrate the data. Configure the source as Couchbase and sink as Azure Cosmos DB SQL API, see the Azure [Cosmos DB Data Factory connector](../data-factory/connector-azure-cosmos-db.md) article for detailed steps.
444+
* **Use Azure Data Factory:** This is the most recommended method to migrate the data. Configure the source as Couchbase and sink as Azure Cosmos DB SQL API, see the Azure [Cosmos DB Data Factory connector](../data-factory/connector-azure-cosmos-db.md) article for detailed steps.
441445

442-
2. **Use the Azure Cosmos DB data import tool:** This option is recommended to migrate using VMs with less amount of data. For detailed steps, see the [Data importer](./import-data.md) article.
446+
* **Use the Azure Cosmos DB data import tool:** This option is recommended to migrate using VMs with less amount of data. For detailed steps, see the [Data importer](./import-data.md) article.
443447

444448
## Next Steps
445449

0 commit comments

Comments
 (0)