Factory function that creates an instance of a statement for adding
documents to a collection.
Methods
-
add(documentsOrJSON)
-
Adds one or more items to the list of documents that the statement will add to the collection. This method does not cause the statement to be executed.
Parameters:
Name Type Description documentsOrJSON
DocumentOrJSON | Array.<DocumentOrJSON> document or list of documents Returns:
The instance of the statement itself following a fluent API convention.- Type
- module:CollectionAdd
Example
// arguments as single documents collection.add({ foo: 'baz' }).add({ bar: 'qux' }, { biz: 'quux' }) // array of documents collection.add([{ foo: 'baz' }]).add([{ bar: 'qux' }, { biz: 'quux' }])
-
execute()
-
Executes the statement in the database that adds the current list of documents to a collection. If a document does not contain an
_id
field, one will be auto-generated and assigned an UUID-like value.- Tutorials:
Returns:
An object containing the details reported by the server.- Type
- Promise.<module:Result>