1MONGOC_COLLECTION_INSERT_ONE(3)MongoDB C DriverMONGOC_COLLECTION_INSERT_ONE(3)
2
3
4

NAME

6       mongoc_collection_insert_one - mongoc_collection_insert_one()
7

SYNOPSIS

9          bool
10          mongoc_collection_insert_one (mongoc_collection_t *collection,
11                                        const bson_t *document,
12                                        const bson_t *opts,
13                                        bson_t *reply,
14                                        bson_error_t *error);
15

PARAMETERS

17       · collection: A mongoc_collection_t.
18
19       · document: A bson_t.
20
21       · reply:  Optional.  An  uninitialized bson_t populated with the insert
22         result, or NULL.
23
24       · error: An optional location for a bson_error_t or NULL.
25
26       opts may be NULL or a BSON document with additional command options:
27
28       · writeConcern:  Construct  a  mongoc_write_concern_t  and   use   mon‐
29         goc_write_concern_append  to  add  the write concern to opts. See the
30         example code for mongoc_client_write_command_with_opts.
31
32       · sessionId:  First,  construct  a  mongoc_client_session_t  with  mon‐
33         goc_client_start_session.  You  can  begin  a  transaction  with mon‐
34         goc_client_session_start_transaction, optionally with a mongoc_trans‐
35         action_opt_t  that  overrides  the options inherited from collection,
36         and use mongoc_client_session_append to add the session to opts.  See
37         the example code for mongoc_client_session_t.
38
39       · validate:     Construct     a     bitwise-or     of    all    desired
40         bson_validate_flags_t. Set to false to skip client-side validation of
41         the provided BSON documents.
42
43       · bypassDocumentValidation: Set to true to skip server-side schema val‐
44         idation of the provided BSON documents.
45

DESCRIPTION

47       This function shall insert document into collection.
48
49       To insert an array of documents, see mongoc_collection_insert_many.
50
51       If no _id element is found in document, then a bson_oid_t will be  gen‐
52       erated locally and added to the document. If you must know the inserted
53       document's _id, generate it in your code and include it  in  the  docu‐
54       ment.  The  _id you generate can be a bson_oid_t or any other non-array
55       BSON type.
56
57       If you pass a non-NULL reply, it is filled out with an  "insertedCount"
58       field.  If  there  is  a  server  error  then  reply  contains either a
59       "writeErrors" array with  one  subdocument  or  a  "writeConcernErrors"
60       array. The reply must be freed with bson_destroy().
61

ERRORS

63       Errors are propagated via the error parameter.
64

RETURNS

66       Returns  true  if successful. Returns false and sets error if there are
67       invalid arguments or a server or network error.
68
69       A write concern timeout or write concern error is considered a failure.
70

AUTHOR

72       MongoDB, Inc
73
75       2017-present, MongoDB, Inc
76
77
78
79
801.15.2                           Nov 06, 2019  MONGOC_COLLECTION_INSERT_ONE(3)
Impressum