MCPcopy Create free account
hub / github.com/couchbase/couchbase-python-client / upsert

Method upsert

couchbase/collection.py:402–463  ·  view source on GitHub ↗

Upserts a document to the collection. This operation succeeds whether or not the document already exists. Args: key (str): Document key to upsert. value (JSONType): The value of the document to upsert. opts (:class:`~couchbase.options.UpsertOptions`): Opt

(
        self,
        key,  # type: str
        value,  # type: JSONType
        *opts,  # type: UpsertOptions
        **kwargs,  # type: Dict[str, Any]
    )

Source from the content-addressed store, hash-verified

400 return self._impl.insert(req, obs_handler)
401
402 def upsert(
403 self,
404 key, # type: str
405 value, # type: JSONType
406 *opts, # type: UpsertOptions
407 **kwargs, # type: Dict[str, Any]
408 ) -> MutationResult:
409 """Upserts a document to the collection. This operation succeeds whether or not the document already exists.
410
411 Args:
412 key (str): Document key to upsert.
413 value (JSONType): The value of the document to upsert.
414 opts (:class:`~couchbase.options.UpsertOptions`): Optional parameters for this operation.
415 **kwargs (Dict[str, Any]): keyword arguments that can be used in place or to
416 override provided :class:`~couchbase.options.UpsertOptions`
417
418 Returns:
419 :class:`~couchbase.result.MutationResult`: An instance of :class:`~couchbase.result.MutationResult`.
420
421 Examples:
422
423 Simple upsert operation::
424
425 bucket = cluster.bucket('travel-sample')
426 collection = bucket.scope('inventory').collection('airline')
427
428 key = 'airline_8091'
429 airline = {
430 "type": "airline",
431 "id": 8091,
432 "callsign": "CBS",
433 "iata": None,
434 "icao": None,
435 "name": "Couchbase Airways",
436 }
437 res = collection.upsert(key, doc)
438
439
440 Simple upsert operation with options::
441
442 from couchbase.durability import DurabilityLevel, ServerDurability
443 from couchbase.options import UpsertOptions
444
445 # ... other code ...
446
447 key = 'airline_8091'
448 airline = {
449 "type": "airline",
450 "id": 8091,
451 "callsign": "CBS",
452 "iata": None,
453 "icao": None,
454 "name": "Couchbase Airways",
455 }
456 durability = ServerDurability(level=DurabilityLevel.MAJORITY)
457 res = collection.upsert(key, doc, InsertOptions(durability=durability))
458
459 """

Callers 15

mainFunction · 0.45
kv_operations.pyFile · 0.45
load_docsFunction · 0.45
usermgmt.pyFile · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
load_docsFunction · 0.45
mainFunction · 0.45
perform_operationsFunction · 0.45
perform_operationsFunction · 0.45

Calls 2

build_upsert_requestMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected