Sets an item within a list at a given position. .. warning:: This method is deprecated and will be removed in the 4.7.0 version. Use :meth:`.CouchbaseList.set_at` instead. Args: key (str): The key for the list document. index (int):
(self,
key: str,
index: int,
value: JSONType,
**kwargs: object
)
| 1272 | return OperationResult(sd_res.cas, sd_res.mutation_token()) |
| 1273 | |
| 1274 | def list_set(self, |
| 1275 | key: str, |
| 1276 | index: int, |
| 1277 | value: JSONType, |
| 1278 | **kwargs: object |
| 1279 | ) -> OperationResult: |
| 1280 | """Sets an item within a list at a given position. |
| 1281 | |
| 1282 | .. warning:: |
| 1283 | This method is deprecated and will be removed in the 4.7.0 version. Use :meth:`.CouchbaseList.set_at` |
| 1284 | instead. |
| 1285 | |
| 1286 | Args: |
| 1287 | key (str): The key for the list document. |
| 1288 | index (int): The position to replace. |
| 1289 | value (JSONType): The value to prepend to the list. |
| 1290 | **kwargs (Dict[str, Any]): keyword arguments that can be used as optional parameters |
| 1291 | for this operation. |
| 1292 | |
| 1293 | Returns: |
| 1294 | :class:`~couchbase.result.OperationResult`: An instance of :class:`~couchbase.result.OperationResult`. |
| 1295 | |
| 1296 | Raises: |
| 1297 | :class:`~couchbase.exceptions.DocumentNotFoundException`: If the key provided does not exist |
| 1298 | on the server. |
| 1299 | IndexError: If the index is out of bounds. |
| 1300 | |
| 1301 | """ |
| 1302 | op_type = DatastructureOperationType.ListSetAt |
| 1303 | with ObservableRequestHandler(op_type, self._impl.observability_instruments) as ds_obs_handler: |
| 1304 | ds_obs_handler.create_kv_span(self._impl._request_builder._collection_dtls.get_details_as_dict()) |
| 1305 | kv_op_type = KeyValueOperationType.MutateIn |
| 1306 | with ObservableRequestHandler(kv_op_type, self._impl.observability_instruments) as obs_handler: |
| 1307 | op = replace(f'[{index}]', value) |
| 1308 | req = self._impl.request_builder.build_mutate_in_request(key, |
| 1309 | (op,), |
| 1310 | obs_handler, |
| 1311 | **kwargs) |
| 1312 | sd_res = self._execute_deprecated_ds_func(self._impl.mutate_in, |
| 1313 | req, |
| 1314 | obs_handler, |
| 1315 | ds_obs_handler.wrapped_span, |
| 1316 | path_value=index) |
| 1317 | return OperationResult(sd_res.cas, sd_res.mutation_token()) |
| 1318 | |
| 1319 | def list_get(self, key: str, index: int, **kwargs: object) -> Any: |
| 1320 | """Get a specific element within a list. |