MCPcopy Index your code
hub / github.com/couchbase/couchbase-python-client / insert

Method insert

couchbase/collection.py:335–400  ·  view source on GitHub ↗

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]
    )

Source from the content-addressed store, hash-verified

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 }

Callers 14

_execute_opMethod · 0.45
_execute_opMethod · 0.45
_execute_opMethod · 0.45
_execute_opMethod · 0.45
conf.pyFile · 0.45
kv_operations.pyFile · 0.45
simple_txns.pyFile · 0.45
runFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 2

build_insert_requestMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected