Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

MongoDB.InsertMany

Insert documents into collection.

Component Version macOS Windows Linux Server iOS SDK
MongoDB 12.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "MongoDB.InsertMany"; MongoDBRef; documentJSON { ; OptionsJSON } )   More

Parameters

Parameter Description Example Flags
MongoDBRef The reference number for the mongo connection. $MongoDB
documentJSON The JSON with an array of the records to save.
OptionsJSON The options to use. Optional

Result

Returns OK or error.

Description

Insert documents into collection.
Please pass a JSON array as string for all documents. Each entry in the array should be a JSON object with the document data.

For any document that does not have an "_id" field, a 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 bson_oid_t or any other non-array BSON type.

The reply is filled out with an "insertedCount" field. If there is a server error then reply may contain a "writeErrors" array and/or a "writeConcernErrors" array.

Examples

Insert two records in one call:

Set Variable [ $JSON ; Value: "[{\"ID\": 1, \"Name\": \"John\"}, {\"ID\": 2, \"Name\": \"Miller\"}]" ]
Set Variable [ $r ; Value: MBS( "MongoDB.InsertMany"; $Mongo; $JSON) ]

Example result:
{ "insertedCount" : 2 }

See also

Release notes

  • Version 12.4

Blog Entries

This function checks for a license.

Created 26th July 2022, last changed 24th September 2022


MongoDB.InTransaction - MongoDB.InsertOne