Skip to main content

Home > git-documentdb > Collection > insert

Collection.insert() method#

Insert a JSON document

Signature:
insert(jsonDoc: JsonDoc, options?: PutOptions): Promise<PutResultJsonDoc>;

Parameters#

ParameterTypeDescription
jsonDocJsonDocJsonDoc whose _id is shortId. shortId is a file path whose collectionPath and extension are omitted.
optionsPutOptions
Returns:

Promise<PutResultJsonDoc >

Remarks#

  • Throws SameIdExistsError when a document that has the same _id exists. It might be better to use put() instead of insert().

  • If _id is undefined, it is automatically generated.

  • The saved file path is ${GitDocumentDB#workingDir}/${Collection#collectionPath}/${jsonDoc._id}${extension} .

Exceptions#

Err.InvalidJsonObjectError

Err.DatabaseClosingError

Err.TaskCancelError

# Errors from validateDocument, validateId

# Errors from putWorker