1MONGOC_COLLECTION_INSERT_ONE(3) libmongoc MONGOC_COLLECTION_INSERT_ONE(3)
2
3
4
6 bool
7 mongoc_collection_insert_one (mongoc_collection_t *collection,
8 const bson_t *document,
9 const bson_t *opts,
10 bson_t *reply,
11 bson_error_t *error);
12
14 • collection: A mongoc_collection_t.
15
16 • document: A bson_t.
17
18 • reply: Optional. An uninitialized bson_t populated with the insert
19 result, or NULL.
20
21 • error: An optional location for a bson_error_t or NULL.
22
23 opts may be NULL or a BSON document with additional command options:
24
25 • writeConcern: Construct a mongoc_write_concern_t and use
26 mongoc_write_concern_append() to add the write concern to opts. See
27 the example code for mongoc_client_write_command_with_opts().
28
29 • sessionId: First, construct a mongoc_client_session_t with
30 mongoc_client_start_session(). You can begin a transaction with
31 mongoc_client_session_start_transaction(), optionally with a
32 mongoc_transaction_opt_t that overrides the options inherited from
33 collection, and use mongoc_client_session_append() to add the session
34 to opts. See the example code for mongoc_client_session_t.
35
36 • validate: Construct a bitwise-or of all desired
37 bson_validate_flags_t. Set to false to skip client-side validation of
38 the provided BSON documents.
39
40 • comment: A bson_value_t specifying the comment to attach to this com‐
41 mand. The comment will appear in log messages, profiler output, and
42 currentOp output. Requires MongoDB 4.4 or later.
43
44 • bypassDocumentValidation: Set to true to skip server-side schema val‐
45 idation of the provided BSON documents.
46
48 This function shall insert document into collection.
49
50 To insert an array of documents, see mongoc_collection_insert_many().
51
52 If no _id element is found in document, then a bson_oid_t will be gen‐
53 erated locally and added to the document. If you must know the inserted
54 document's _id, generate it in your code and include it in the docu‐
55 ment. The _id you generate can be a bson_oid_t or any other non-array
56 BSON type.
57
58 If you pass a non-NULL reply, it is filled out with an "insertedCount"
59 field. If there is a server error then reply contains either a
60 "writeErrors" array with one subdocument or a "writeConcernErrors" ar‐
61 ray. The reply must be freed with bson_destroy().
62
64 Errors are propagated via the error parameter.
65
67 Returns true if successful. Returns false and sets error if there are
68 invalid arguments or a server or network error.
69
70 A write concern timeout or write concern error is considered a failure.
71
73 MongoDB, Inc
74
76 2017-present, MongoDB, Inc
77
78
79
80
811.25.1 Nov 08, 2023 MONGOC_COLLECTION_INSERT_ONE(3)