1MONGOC_COLLECTION_INSERT_MANY(3) libmongoc MONGOC_COLLECTION_INSERT_MANY(3)
2
3
4
6 bool
7 mongoc_collection_insert_many (mongoc_collection_t *collection,
8 const bson_t **documents,
9 size_t n_documents,
10 const bson_t *opts,
11 bson_t *reply,
12 bson_error_t *error);
13
15 • collection: A mongoc_collection_t.
16
17 • documents: An array of pointers to bson_t.
18
19 • n_documents: The length of documents.
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
29 mongoc_write_concern_append() to add the write concern to opts. See
30 the example code for mongoc_client_write_command_with_opts().
31
32 • sessionId: First, construct a mongoc_client_session_t with
33 mongoc_client_start_session(). You can begin a transaction with
34 mongoc_client_session_start_transaction(), optionally with a
35 mongoc_transaction_opt_t that overrides the options inherited from
36 collection, and use mongoc_client_session_append() to add the session
37 to opts. See 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 • comment: A bson_value_t specifying the comment to attach to this com‐
44 mand. The comment will appear in log messages, profiler output, and
45 currentOp output. Requires MongoDB 4.4 or later.
46
47 • ordered: set to false to attempt to insert all documents, continuing
48 after errors.
49
50 • bypassDocumentValidation: Set to true to skip server-side schema val‐
51 idation of the provided BSON documents.
52
54 Insert documents into collection.
55
56 To insert a single document, see mongoc_collection_insert_one().
57
58 For any document that does not have an "_id" field, a bson_oid_t will
59 be generated locally and added to the document. If you must know the
60 inserted document's _id, generate it in your code and include it in the
61 document. The _id you generate can be a bson_oid_t or any other non-ar‐
62 ray BSON type.
63
64 If you pass a non-NULL reply, it is filled out with an "insertedCount"
65 field. If there is a server error then reply may contain a "writeEr‐
66 rors" array and/or a "writeConcernErrors" array (see Bulk Write Opera‐
67 tions for examples). The reply must be freed with bson_destroy().
68
70 Errors are propagated via the error parameter.
71
73 Returns true if successful. Returns false and sets error if there are
74 invalid arguments or a server or network error.
75
76 A write concern timeout or write concern error is considered a failure.
77
79 MongoDB, Inc
80
82 2017-present, MongoDB, Inc
83
84
85
86
871.25.1 Nov 08, 2023 MONGOC_COLLECTION_INSERT_MANY(3)