Skip to content

Commit 7811766

Browse files
committed
update samples
1 parent a008ed0 commit 7811766

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +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+
}
115126
```
116127

117128
### [JavaScript](#tab/javascript)
118129

119130
```javascript
120-
const { resource: contDefinition } = await containerWithComputedProperty.read();
121-
const upperName = {
122-
name: "upperLastName", query: "SELECT VALUE UPPER(IS_DEFINED(c.lastName) ? c.lastName : c.parents[0].familyName) FROM c",
131+
const lowerName = {
132+
name: "lowerLastName",
133+
query:
134+
"SELECT VALUE LOWER(IS_DEFINED(c.lastName) ? c.lastName : c.parents[0].familyName) FROM c",
123135
};
124-
if (contDefinition) {
125-
// update computed properties contDefinition.computedProperties = [upperName]; // replace container definition with updated computed properties await containerWithComputedProperty.replace(contDefinition); console.log("Computed properties updated");
126-
} else {
127-
console.log("Container definition is undefined.");
128-
}
136+
137+
const { container: containerWithComputedProperty } = await database.containers.createIfNotExists({
138+
id: containerId,
139+
computedProperties: [lowerName],
140+
});
129141
```
130142

131143
### [Python](#tab/python)

0 commit comments

Comments
 (0)