Whenever we create a database with Orama, we must specify a schema, which
represents the entry we are going to index.
Let’s say our database and schema look like this:
(Read more about database creation on the create page)
Insert
Data insertion in Orama is quick and intuitive:
If you have a lot of records, we suggest using the insertMultiple function as following:
Inserting a large number of documents in a loop could potentially block the event loop.
Instead insertMultiple handles this case better.
You can pass a third, optional, parameter to change the batch size (default:
1000). We recommend keeping this number as low as possible to avoid blocking
the event loop. The batchSize refers to the maximum number of insert
operations to perform before yielding the event loop.
Validation rules
Defining the schema at database creation time, Orama validates all the inserted documents following those rules:
throw an error if a field has an unexpected type
allow missing fields or fields set to undefined
allow extra fields ignoring them
So the following document will be accepted:
Custom document IDs
Orama automatically uses the id field of the document, if found.
That means that given the following document and schema:
the document will be indexed with the following id: 73cbcc79-2203-49b8-bb52-60d8e9a66c5f.
Remote document storing
By default Orama keeps a copy of the inserted document in memory (and in the serialized data) to speed up search performance.
If this is not acceptable, you can provide a custom documentsStore component which will be responsible to store
and fetch documents from another location (local or remote).
The code example below is an example that implements a proxy: when a document is requested, the code finds it on a location of the filesystem.
We assume each document has an id field which disable Orama random ID generation.
You can replace the file related operations with your custom code.