Skip to content

Commit de875be

Browse files
Merge pull request #283675 from sajeetharan/javascript_4.1
JS SDK 4.1 updates
2 parents e38e8f6 + 7811766 commit de875be

File tree

3 files changed

+77
-6
lines changed

3 files changed

+77
-6
lines changed

articles/cosmos-db/nosql/change-feed-modes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ During the preview, the following methods to read the change feed are available
120120

121121
| **Method to read change feed** | **.NET** | **Java** | **Python** | **Node.js** |
122122
| --- | --- | --- | --- | --- |
123-
| [Change feed pull model](change-feed-pull-model.md) | [>= 3.32.0-preview](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.32.0-preview) | [>= 4.42.0](https://mvnrepository.com/artifact/com.azure/azure-cosmos/4.37.0) | No | No |
124-
| [Change feed processor](change-feed-processor.md) | [>= 3.40.0-preview.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.40.0-preview.0) | [>= 4.42.0](https://mvnrepository.com/artifact/com.azure/azure-cosmos/4.42.0) | No | No |
123+
| [Change feed pull model](change-feed-pull-model.md) | [>= 3.32.0-preview](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.32.0-preview) | [>= 4.42.0](https://mvnrepository.com/artifact/com.azure/azure-cosmos/4.37.0) | No | [>= 4.1.0](https://www.npmjs.com/package/@azure/cosmos/v/4.1.0) |
124+
| [Change feed processor](change-feed-processor.md) | No | [>= 4.42.0](https://mvnrepository.com/artifact/com.azure/azure-cosmos/4.42.0) | No | No |
125125
| Azure Functions trigger | No | No | No | No |
126126

127127
> [!NOTE]

articles/cosmos-db/nosql/how-to-manage-indexing-policy.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,37 @@ const containerResponse = await client.database('database').container('container
601601
// retrieve the index transformation progress from the response headers
602602
const indexTransformationProgress = replaceResponse.headers['x-ms-documentdb-collection-index-transformation-progress'];
603603
```
604+
Add a composite index:
605+
606+
```javascript
607+
console.log("create container with composite indexes");
608+
const containerDefWithCompositeIndexes = {
609+
id: "containerWithCompositeIndexingPolicy",
610+
indexingPolicy: {
611+
automatic: true,
612+
indexingMode: IndexingMode.consistent,
613+
includedPaths: [
614+
{
615+
path: "/*",
616+
},
617+
],
618+
excludedPaths: [
619+
{
620+
path: '/"systemMetadata"/*',
621+
},
622+
],
623+
compositeIndexes: [
624+
[
625+
{ path: "/field", order: "ascending" },
626+
{ path: "/key", order: "ascending" },
627+
],
628+
],
629+
},
630+
};
631+
const containerWithCompositeIndexes = (
632+
await database.containers.create(containerDefWithCompositeIndexes)
633+
).container;
634+
```
604635

605636
### Use the Python SDK
606637

articles/cosmos-db/nosql/query/computed-properties.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,36 @@ Container container = await client.GetDatabase("myDatabase").CreateContainerAsyn
108108
### [Java](#tab/java)
109109

110110
```java
111-
CosmosContainerProperties containerProperties = new CosmosContainerProperties("myContainer", "/pk");
112-
List<ComputedProperty> computedProperties = new ArrayList<>(List.of(new ComputedProperty("cp_lowerName", "SELECT VALUE LOWER(c.name) FROM c")));
113-
containerProperties.setComputedProperties(computedProperties);
114-
client.getDatabase("myDatabase").createContainer(containerProperties);
111+
const { resource: contDefinition } = await containerWithComputedProperty.read();
112+
const upperName = {
113+
name: "upperLastName",
114+
query:
115+
"SELECT VALUE UPPER(IS_DEFINED(c.lastName) ? c.lastName : c.parents[0].familyName) FROM c",
116+
};
117+
if (contDefinition) {
118+
// update computed properties
119+
contDefinition.computedProperties = [upperName];
120+
// replace container definition with updated computed properties
121+
await containerWithComputedProperty.replace(contDefinition);
122+
console.log("Computed properties updated");
123+
} else {
124+
console.log("Container definition is undefined.");
125+
}
126+
```
127+
128+
### [JavaScript](#tab/javascript)
129+
130+
```javascript
131+
const lowerName = {
132+
name: "lowerLastName",
133+
query:
134+
"SELECT VALUE LOWER(IS_DEFINED(c.lastName) ? c.lastName : c.parents[0].familyName) FROM c",
135+
};
136+
137+
const { container: containerWithComputedProperty } = await database.containers.createIfNotExists({
138+
id: containerId,
139+
computedProperties: [lowerName],
140+
});
115141
```
116142

117143
### [Python](#tab/python)
@@ -177,6 +203,20 @@ containerProperties.setComputedProperties(modifiedComputedProperites);
177203
container.replace(containerProperties);
178204
```
179205

206+
### [JavaScript](#tab/javascript)
207+
208+
```javascript
209+
const { resource: contDefinition } = await containerWithComputedProperty.read();
210+
const upperName = {
211+
name: "upperLastName", query: "SELECT VALUE UPPER(IS_DEFINED(c.lastName) ? c.lastName : c.parents[0].familyName) FROM c",
212+
};
213+
if (contDefinition) {
214+
// update computed properties contDefinition.computedProperties = [upperName]; // replace container definition with updated computed properties await containerWithComputedProperty.replace(contDefinition); console.log("Computed properties updated");
215+
} else {
216+
console.log("Container definition is undefined.");
217+
}
218+
```
219+
180220
### [Python](#tab/python)
181221
Updating computed properties on an existing container is not supported in Python SDK. You can only define computed properties when creating a new container. This is a work in progress currently.
182222

0 commit comments

Comments
 (0)