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

Method insert

acouchbase/collection.py:297–362  ·  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,
                     key,  # type: str
                     value,  # type: JSONType
                     *opts,  # type: InsertOptions
                     **kwargs,  # type: Any
                     )

Source from the content-addressed store, hash-verified

295 return await self._impl.exists(req, obs_handler)
296
297 async def insert(self,
298 key, # type: str
299 value, # type: JSONType
300 *opts, # type: InsertOptions
301 **kwargs, # type: Any
302 ) -> MutationResult:
303 """Inserts a new document to the collection, failing if the document already exists.
304
305 Args:
306 key (str): Document key to insert.
307 value (JSONType): The value of the document to insert.
308 opts (:class:`~couchbase.options.InsertOptions`): Optional parameters for this operation.
309 **kwargs (Dict[str, Any]): keyword arguments that can be used in place or to
310 override provided :class:`~couchbase.options.InsertOptions`
311
312 Returns:
313 Awaitable[:class:`~couchbase.result.MutationResult`]: A future that contains an instance
314 of :class:`~couchbase.result.MutationResult` if successful.
315
316 Raises:
317 :class:`~couchbase.exceptions.DocumentExistsException`: If the document already exists on the
318 server.
319
320 Examples:
321
322 Simple insert operation::
323
324 bucket = cluster.bucket('travel-sample')
325 collection = bucket.scope('inventory').collection('airline')
326
327 key = 'airline_8091'
328 airline = {
329 "type": "airline",
330 "id": 8091,
331 "callsign": "CBS",
332 "iata": None,
333 "icao": None,
334 "name": "Couchbase Airways",
335 }
336 res = await collection.insert(key, doc)
337
338
339 Simple insert operation with options::
340
341 from couchbase.durability import DurabilityLevel, ServerDurability
342 from couchbase.options import InsertOptions
343
344 # ... other code ...
345
346 key = 'airline_8091'
347 airline = {
348 "type": "airline",
349 "id": 8091,
350 "callsign": "CBS",
351 "iata": None,
352 "icao": None,
353 "name": "Couchbase Airways",
354 }

Callers 4

_execute_opMethod · 0.45
_execute_opMethod · 0.45
_execute_opMethod · 0.45
_execute_opMethod · 0.45

Calls 2

build_insert_requestMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected