Skip to main content

Home > git-documentdb > Collection > getOldRevision

Collection.getOldRevision() method#

Get an old revision of a JSON document

Signature:
getOldRevision(shortId: string, revision: number, historyOptions?: HistoryOptions): Promise<JsonDoc | undefined>;

Parameters#

ParameterTypeDescription
shortIdstringshortId is a file path whose collectionPath and extension are omitted.
revisionnumberSpecify a number to go back to old revision. Default is 0. See Collection.getHistory() for the array of revisions.
historyOptionsHistoryOptionsThe array of revisions is filtered by HistoryOptions.filter.
Returns:

Promise<JsonDoc | undefined>

Remarks#

  • undefined if a specified document does not exist or it is deleted.

  • If serializeFormat is front-matter, this function can't correctly distinguish files that has the same _id but different extension. Use getFatDocOldRevision() instead. e.g.) foo.md and foo.yml

Example#

collection.getOldRevision(_shortId, 0); // returns the latest document.
collection.getOldRevision(_shortId, 2); // returns a document two revisions older than the latest.

Exceptions#

Err.DatabaseClosingError

Err.InvalidJsonObjectError