Skip to main content

Home > git-documentdb > Collection

Collection class#

Documents under a collectionPath are gathered together in a collection.

export declare class Collection implements ICollection



In a collection API, shortId (shortName) is used instead of _id (name).

  • shortId is a file path whose collectionPath and extension are omitted. (_id = collectionPath + shortId)

  • shortName is a file path whose collectionPath is omitted. (name = collectionPath + shortName)


const gitDDB = new GitDocumentDB({ db_name: 'db01' });
// Both put git_documentdb/db01/Nara/flower.json: { _id: 'Nara/flower', name: 'cherry blossoms' }.
gitDDB.put({ _id: 'Nara/flower', name: 'cherry blossoms' });
gitDDB.collection('Nara').put({ _id: 'flower', name: 'cherry blossoms' })
// Notice that APIs return different _id values despite the same source file.
gitDDB.get({ _id: 'Nara/flower' }); // returns { _id: 'Nara/flower', name: 'cherry blossoms' }.
gitDDB.collection('Nara').get({ _id: 'flower' }); // returns { _id: 'flower', name: 'cherry blossoms' }.


(constructor)(gitDDB, collectionPathFromParent, parent, options)Constructor


collectionPathstringNormalized path of a collection
optionsCollectionOptionsGet a clone of collection options
parentICollection | undefinedParent collection


collection(collectionPath, options)Get a collection
delete(_id, options)Delete a JSON document
delete(jsonDoc, options)Delete a document by _id property in JsonDoc
deleteFatDoc(shortName, options)Delete a data
find(options)Get all the JSON documents
findFatDoc(options)Get all the FatDoc data
generateId(seedTime)Generate new _id as monotonic ULID
get(_id)Get a JSON document
getCollections(dirPath)Get collections directly under the specified dirPath.
getDocByOid(fileOid, docType)Get a Doc which has specified oid
getFatDoc(shortName, getOptions)Get a FatDoc data
getFatDocHistory(shortName, historyOptions, getOptions)Get revision history of a FatDoc data
getFatDocOldRevision(shortName, revision, historyOptions, getOptions)Get an old revision of a FatDoc data
getHistory(_id, historyOptions)Get revision history of a JSON document
getOldRevision(shortId, revision, historyOptions)Get an old revision of a JSON document
insert(jsonDoc, options)Insert a JSON document
insert(shortId, jsonDoc, options)Insert a JSON document
insertFatDoc(shortName, doc, options)Insert a data
offSyncEvent(remoteURL, event, callback)Remove SyncEvent handler
offSyncEvent(sync, event, callback)Remove SyncEvent handler
onSyncEvent(remoteURL, event, callback)Add SyncEvent handler
onSyncEvent(sync, event, callback)Add SyncEvent handler
put(jsonDoc, options)Insert a JSON document if not exists. Otherwise, update it.
put(shortId, jsonDoc, options)Insert a JSON document if not exists. Otherwise, update it.
putFatDoc(shortName, doc, options)Insert data if not exists. Otherwise, update it.
update(jsonDoc, options)Update a JSON document
update(_id, jsonDoc, options)Update a JSON document
updateFatDoc(shortName, doc, options)Update a data