Inserts a new document to the collection, failing if the document already exists. Args: key (str): Document key to insert. value (JSONType): The value of the document to insert. opts (:class:`~couchbase.options.InsertOptions`): Optional parameters for thi
(
self, # type: "Collection"
key, # type: str
value, # type: JSONType
*opts, # type: InsertOptions
**kwargs, # type: Dict[str, Any]
)
| 333 | return self._impl.exists(req, obs_handler) |
| 334 | |
| 335 | def insert( |
| 336 | self, # type: "Collection" |
| 337 | key, # type: str |
| 338 | value, # type: JSONType |
| 339 | *opts, # type: InsertOptions |
| 340 | **kwargs, # type: Dict[str, Any] |
| 341 | ) -> MutationResult: |
| 342 | """Inserts a new document to the collection, failing if the document already exists. |
| 343 | |
| 344 | Args: |
| 345 | key (str): Document key to insert. |
| 346 | value (JSONType): The value of the document to insert. |
| 347 | opts (:class:`~couchbase.options.InsertOptions`): Optional parameters for this operation. |
| 348 | **kwargs (Dict[str, Any]): keyword arguments that can be used in place or to |
| 349 | override provided :class:`~couchbase.options.InsertOptions` |
| 350 | |
| 351 | Returns: |
| 352 | :class:`~couchbase.result.MutationResult`: An instance of :class:`~couchbase.result.MutationResult`. |
| 353 | |
| 354 | Raises: |
| 355 | :class:`~couchbase.exceptions.DocumentExistsException`: If the document already exists on the |
| 356 | server. |
| 357 | |
| 358 | Examples: |
| 359 | |
| 360 | Simple insert operation:: |
| 361 | |
| 362 | bucket = cluster.bucket('travel-sample') |
| 363 | collection = bucket.scope('inventory').collection('airline') |
| 364 | |
| 365 | key = 'airline_8091' |
| 366 | airline = { |
| 367 | "type": "airline", |
| 368 | "id": 8091, |
| 369 | "callsign": "CBS", |
| 370 | "iata": None, |
| 371 | "icao": None, |
| 372 | "name": "Couchbase Airways", |
| 373 | } |
| 374 | res = collection.insert(key, doc) |
| 375 | |
| 376 | |
| 377 | Simple insert operation with options:: |
| 378 | |
| 379 | from couchbase.durability import DurabilityLevel, ServerDurability |
| 380 | from couchbase.options import InsertOptions |
| 381 | |
| 382 | # ... other code ... |
| 383 | |
| 384 | key = 'airline_8091' |
| 385 | airline = { |
| 386 | "type": "airline", |
| 387 | "id": 8091, |
| 388 | "callsign": "CBS", |
| 389 | "iata": None, |
| 390 | "icao": None, |
| 391 | "name": "Couchbase Airways", |
| 392 | } |
no test coverage detected