File: mongoc_collection_insert.rst

package info (click to toggle)
mongo-c-driver 1.17.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 37,256 kB
  • sloc: ansic: 152,613; javascript: 7,954; python: 3,259; sh: 138; makefile: 29; xml: 10
file content (47 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
:man_page: mongoc_collection_insert

mongoc_collection_insert()
==========================

Synopsis
--------

.. code-block:: c

  bool
  mongoc_collection_insert (mongoc_collection_t *collection,
                            mongoc_insert_flags_t flags,
                            const bson_t *document,
                            const mongoc_write_concern_t *write_concern,
                            bson_error_t *error);

Parameters
----------

* ``collection``: A :symbol:`mongoc_collection_t`.
* ``flags``: A :symbol:`mongoc_insert_flags_t`.
* ``document``: A :symbol:`bson:bson_t`.
* ``write_concern``: A :symbol:`mongoc_write_concern_t`.
* ``error``: An optional location for a :symbol:`bson_error_t <errors>` or ``NULL``.

Description
-----------

Superseded by :symbol:`mongoc_collection_insert_one()` and :symbol:`mongoc_collection_insert_many()`.

This function shall insert ``document`` into ``collection``.

If no ``_id`` element is found in ``document``, then a :symbol:`bson:bson_oid_t` will be generated locally and added to the document. If you must know the inserted document's ``_id``, generate it in your code and include it in the ``document``. The ``_id`` you generate can be a :symbol:`bson:bson_oid_t` or any other non-array BSON type.

Errors
------

Errors are propagated via the ``error`` parameter.

Returns
-------

Returns ``true`` if successful. Returns ``false`` and sets ``error`` if there are invalid arguments or a server or network error.

A write concern timeout or write concern error is considered a failure.