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