DAB
Search…
bulkCreate
1
bulkCreate(body, param)
Copied!

Arguments

Body (array, required)

Body is always an array of objects. If no ID is not provided, it'll be generated automatically for you. Example:
1
[
2
{ _id: 'james-bond', name: 'James Bond' },
3
{ _id: 'jack-bauer', name: 'Jack Bauer' },
4
{ name: 'Johnny English' } // ID isn't provided here, it'll be created automatically
5
...
6
]
Copied!

Params (required)

  • collection: Required, the name of collection you want to work with.
  • withDetail: Optional, defaults to false. If true, details of operation will be returned. It is an array of objects in the same order as body request above. See example below.

Response

Method should always return a response, eventhough one or more insertion could fail. If failed, those corresponding rows should tell why it failed, assuming it is enabled through withDetail parameter above.
The order of insertion result should match with the order of body request.
Promise rejection error should only occour when something very bad happened within the script.
Example:
1
{
2
success: true,
3
stat: {
4
ok: 2,
5
fail: 1,
6
total: 3
7
},
8
detail: [
9
{ _id: 'james-bond', success: false, message: 'Document already exists' },
10
{ _id: 'jack-bauer', success: true },
11
{ _id: '337b116d-650e-4581-8bef-7b119467b05c', success: true }
12
]
13
}
Copied!
Last modified 3yr ago