Storing a collection as an object within a file
This page describes how to set up persistent file storage for a collection using Nabu, where the documents are stored as an object within a single file with the ID as key and the rest of the document as value
Object in file storage requires the Nabu storage engine
To configure a single collection to be stored as an object in file we can specify the storageEngine
option when creating the collection.
Insert a couple of documents
After the insert operation above content/myCollection.yaml
will contain the following:
By defining a custom I/O rule for the storage engine, we can reuse the same configuration across multiple collections. Here we create a rule called objectInYaml
that we can target when creating the collection.
Alternatively we can set the default I/O rule and skip the storageEngine
option entirely.
By specifying a field
option we can store a complete database within the same file. In the following example we set up the I/O so that the YAML-file contains an object where keys correspond to names of collections.
Content on disk
path: string
Path to the file where documents are stored
format: string
File format. The current valid file formats include:
format: 'json'
format: 'yaml'
field?: string
An optional name of the field under which the documents are stored in the file. When omitted the list of documents are stored at the root
Note that field
supports nesting, eg: 'foo.bar'
is valid
input?: Document[]
Optional additional pipeline stages to apply after documents have been read from file.
When using this option, make sure that output
is also present and does the inverse transformation of `input.
output?: Document[]
Optional additional pipeline stages to apply before documents are written to file.
When using this option, make sure that input
is also present and does the inverse transformation of output
.