Skip to main content

Prefix search

/**
Create documents under sub-directories
git-documentdb
โ””โ”€โ”€ db01
โ”œโ”€โ”€ nara
โ”‚ โ”œโ”€โ”€ nara_park.json
โ”‚ โ””โ”€โ”€ tsukigase.json
โ””โ”€โ”€ yoshino
โ””โ”€โ”€ mt_yoshino.json
*/
await gitDDB.put({ _id: 'nara/nara_park', flower: 'double cherry blossoms' });
await gitDDB.put({ _id: 'nara/tsukigase', flower: 'Japanese apricot' });
await gitDDB.put({ _id: 'yoshino/mt_yoshino', flower: 'awesome cherry blossoms' });
// Read
const flowerInYoshino = await gitDDB.get('yoshino/mt_yoshino');
console.log(flowerInYoshino);
// log:: { flower: 'awesome cherry blossoms', _id: 'yoshino/mt_yoshino' }
/**
* Prefix search
*
* Read all the documents whose IDs start with the prefix.
*/
const flowersInNara = await gitDDB.find({ prefix: 'nara/' });
console.log(flowersInNara);
/* log:
[
{ flower: 'double cherry blossoms', _id: 'nara/nara_park' },
{ flower: 'Japanese apricot', _id: 'nara/tsukigase' }
]
*/
// destroy() closes DB and removes
// both the Git repository and the working directory.
await gitDDB.destroy();