insertMany
Adds multiple records to a collection.
Method definition
insertMany(docs: object[]): Promise<MongoResult>Request parameters
Field name | Type | Required | Description |
| Array | Yes | The data to insert. This must be an array of objects, where each object is a record. |
The value of the docs parameter cannot be an empty array (
[]).The
_idfield is reserved by the system. A value is automatically assigned when you insert data. If you specify a value for this field, it must be in theObjectIdformat. The value must be 24 characters long and contain only numbers (0-9) and letters (a-z, A-Z).A field value that matches the
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'format is automatically converted to a date format. For example, 2022-01-30T08:00:00.000Z. You can use the converted date value for conditional queries.
Request example
Insert two records into the users collection.
mpserverless.db.collection('users').insertMany([{
name: 'tom',
age: 1
}, {
name: 'jerry',
age: 2
}])
.then(res => {})
.catch(console.error)Result example
The request succeeded:
{
"affectedDocs": 2,
"result": { "0": "630f4feaf43e60d6a33dcd52", "1": "630f4feaf43e60d6a33dcd53" },
"success": true
}