Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 11.3   11.4   11.5   12.0   12.1   12.2   12.3   12.4   12.5   13.0    Statistic    FMM    Blog  


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


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


Returns OK or error.


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.


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

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

MongoDB.InTransaction - MongoDB.InsertOne

Feedback: Report problem or ask question.

Start Chat