A single KongoDB database, exposed as a Milton folder resource whose children are the JSON documents it contains. New documents are created by PUTting JSON content to a child path, or via the createNew, findByType and search methods exported to server-side JavaScript. Documents can be looked up by type and name, searched against the database's Elasticsearch index, and the index type mappings can be updated and the database reindexed from here.
Group: Resources
Extends: AbstractJsonResource
Implements: CommonCollectionResource, PutableResource
Properties
| Property | Returns | Description |
|---|---|---|
| allowAccess | boolean | Whether this database can be accessed from any website in the organisation, rather than only the website it is associated with. |
| allowRest | boolean | Whether documents in this database can be read and written over the REST API using the raw JSON content type, in addition to the admin UI. |
| children | List<? extends Resource> | All documents currently stored in this database, loaded and cached on first access. This is an expensive lookup involving a database query the first time it is called. |
| indexName | String | Name of the Elasticsearch index backing this database's documents. |
| numRecords | long | Number of documents currently stored in this database. This is an expensive lookup involving a database count query. |
| readonly | boolean | Whether this database rejects writes. When true, attempts to replace a document's content throw BadRequestException. |
| template | String | Name of the document template configured for this database, used to identify the kind of documents it holds. May be null if no template has been set. |
| title | String | Display title of the database, or its name if no title has been set. Used as the page title when this folder is rendered. |
| website | String | Name of the website this database is associated with, or null if it is not associated with a particular website. Unless the allow-access flag is set, the database can only be reached from the website it is configured for. |
Methods
getTitle() · getChildren() · findByType(String type) · findByTypeAndName(String type, String name) · findByTypeAndPrefix(String type, String idPrefix) · findByTypeAndPrefix(String type, String idPrefix, SearchProperties searchProperties) · getNumRecords() · deleteDocument(JsonDocument doc) · createNew(String newName, String json) · createNew(String newName, String json, String docType) · search(String query) · search(String query, Integer pageSize) · getTemplate() · updateTypeMappings(String type, String mapping) · updateTypeMappings(Map<String,String> mappings) · updateTypeMappings(Map<String,String> mappings, Consumer<OnReindexProgressEvent> callback) · setTitle(String title) · setName(String name) · setTemplate(String template) · getWebsite() · setWebsite(String websiteName) · isAllowRest() · setAllowRest(boolean allowRest) · isReadonly() · setReadonly(boolean readonly) · isAllowAccess() · setAllowAccess(Boolean allowAccess) · reindex() · reindex(Consumer<OnReindexProgressEvent> callback) · getIndexName()
getTitle()
Returns: String
Display title of the database, or its name if no title has been set. Used as the page title when this folder is rendered.
getChildren()
Returns: List<? extends Resource>
All documents currently stored in this database, loaded and cached on first access. This is an expensive lookup involving a database query the first time it is called.
findByType(String type)
Returns: ResourceList<JsonDocumentResource>
Finds all documents in this database with the given document type. This is an expensive lookup involving a database query.
| Parameter | Description |
|---|---|
type | the document type to match |
findByTypeAndName(String type, String name)
Returns: JsonDocumentResource
Finds a single document of the given type whose name matches. This is an expensive lookup involving a database query. If more than one document matches, a warning is logged and the first result is returned.
| Parameter | Description |
|---|---|
type | the document type to match |
name | the document name to match |
findByTypeAndPrefix(String type, String idPrefix)
Returns: ResourceList<JsonDocumentResource>
Finds documents of the given type whose ID starts with the given prefix. For example, for a document ID like "customer1-something1", searching with the prefix "customer1" will match. This is an expensive lookup involving a database query.
| Parameter | Description |
|---|---|
type | the document type to match |
idPrefix | a prefix, or full value, of the document ID to match |
findByTypeAndPrefix(String type, String idPrefix, SearchProperties searchProperties)
Returns: ResourceList<JsonDocumentResource>
Finds documents of the given type whose ID starts with the given prefix, with paging applied. This is an expensive lookup involving a database query.
| Parameter | Description |
|---|---|
type | the document type to match |
idPrefix | a prefix, or full value, of the document ID to match |
searchProperties | paging settings to apply to the query, may be null for no paging |
getNumRecords()
Returns: long
Number of documents currently stored in this database. This is an expensive lookup involving a database count query.
deleteDocument(JsonDocument doc)
Returns: void
Removes a document's entry from this database's Elasticsearch index. This only clears the search index entry; it does not delete the underlying document record.
| Parameter | Description |
|---|---|
doc | the document to remove from the search index |
createNew(String newName, String json)
Returns: Resource
Creates a new document in this database from a JSON string, using the document's name as its type. This is an expensive operation involving a database write and a search index update.
| Parameter | Description |
|---|---|
newName | the name of the new document, used as its ID and also as its document type |
json | the JSON content of the new document |
createNew(String newName, String json, String docType)
Returns: Resource
Creates a new document in this database from a JSON string, with an explicit document type. This is an expensive operation involving a database write and a search index update.
| Parameter | Description |
|---|---|
newName | the name of the new document, used as its ID |
json | the JSON content of the new document |
docType | the document's type |
search(String query)
Returns: KSearchResponse
Runs a free-text search against this database's Elasticsearch index using the default page size. This is an expensive operation involving a call to the search index.
| Parameter | Description |
|---|---|
query | the search query text |
search(String query, Integer pageSize)
Returns: KSearchResponse
Runs a free-text search against this database's Elasticsearch index with an explicit page size. This is an expensive operation involving a call to the search index.
| Parameter | Description |
|---|---|
query | the search query text |
pageSize | the maximum number of hits to return |
getTemplate()
Returns: String
Name of the document template configured for this database, used to identify the kind of documents it holds. May be null if no template has been set.
updateTypeMappings(String type, String mapping)
Returns: void
Adds or updates a single Elasticsearch type mapping for this database. Because Elasticsearch generally does not allow an existing type mapping to be changed, this deletes the index, restores the prior type mappings plus the new one, and then re-indexes all documents in the database. This is an expensive operation.
| Parameter | Description |
|---|---|
type | the document type the mapping applies to |
mapping | the mapping definition, as JSON |
updateTypeMappings(Map<String,String> mappings)
Returns: void
Adds or updates several Elasticsearch type mappings for this database. Each entry in the map must have the document type as its key and the mapping definition, as JSON, as its value. This rebuilds the index and re-indexes all documents in the database, so is an expensive operation.
| Parameter | Description |
|---|---|
mappings | a map of document type to mapping definition JSON |
updateTypeMappings(Map<String,String> mappings, Consumer<OnReindexProgressEvent> callback)
Returns: void
Adds or updates several Elasticsearch type mappings for this database, reporting progress as re-indexing proceeds. Each entry in the map must have the document type as its key and the mapping definition, as JSON, as its value. This rebuilds the index and re-indexes all documents in the database, so is an expensive operation.
| Parameter | Description |
|---|---|
mappings | a map of document type to mapping definition JSON |
callback | invoked with progress events as re-indexing proceeds, may be null |
setTitle(String title)
Returns: void
Sets the display title of this database and persists the change immediately.
| Parameter | Description |
|---|---|
title | the new title |
setName(String name)
Returns: boolean
Sets the name of this database and persists the change immediately, provided no other database in the organisation already uses the given name.
| Parameter | Description |
|---|---|
name | the new name |
setTemplate(String template)
Returns: void
Sets the document template name for this database and persists the change immediately.
| Parameter | Description |
|---|---|
template | the new template name |
getWebsite()
Returns: String
Name of the website this database is associated with, or null if it is not associated with a particular website. Unless the allow-access flag is set, the database can only be reached from the website it is configured for.
setWebsite(String websiteName)
Returns: void
Associates this database with a website by name and persists the change immediately. Logs a warning and makes no change if no website with the given name exists in the organisation.
| Parameter | Description |
|---|---|
websiteName | the name of the website to associate with this database |
isAllowRest()
Returns: boolean
Whether documents in this database can be read and written over the REST API using the raw JSON content type, in addition to the admin UI.
setAllowRest(boolean allowRest)
Returns: void
Sets whether documents in this database can be read and written over the REST API, and persists the change immediately.
| Parameter | Description |
|---|---|
allowRest | true to allow REST access to this database |
isReadonly()
Returns: boolean
Whether this database rejects writes. When true, attempts to replace a document's content throw BadRequestException.
setReadonly(boolean readonly)
Returns: void
Sets whether this database rejects writes, and persists the change immediately.
| Parameter | Description |
|---|---|
readonly | true to make this database read-only |
isAllowAccess()
Returns: boolean
Whether this database can be accessed from any website in the organisation, rather than only the website it is associated with.
setAllowAccess(Boolean allowAccess)
Returns: void
Sets whether this database can be accessed from any website in the organisation, and persists the change immediately.
| Parameter | Description |
|---|---|
allowAccess | true to allow access from any website |
reindex()
Returns: void
Rebuilds this database's Elasticsearch index from its current documents. This is an expensive operation that reads and re-indexes every document in the database.
reindex(Consumer<OnReindexProgressEvent> callback)
Returns: void
Rebuilds this database's Elasticsearch index from its current documents, reporting progress as it goes. This is an expensive operation that reads and re-indexes every document in the database.
| Parameter | Description |
|---|---|
callback | invoked with progress events as re-indexing proceeds, may be null |
getIndexName()
Returns: String
Name of the Elasticsearch index backing this database's documents.