Quick Start
- Last Updated:February 19, 2025
- 6 minute read
- MarkLogic Server
- Version 10.0
- Documentation
You can configure MarkLogic Server to manage and query temporal data.
This chapter walks you through the procedures for configuring the Documents
database to store temporal documents and for inserting and querying temporal documents. The following are the main sections:
- Create Metadata Fields for the Valid and System Axes
- Create Range Field Indexes for the Valid and System Axes
- Create System and Valid Axes
- Create a Temporal Collection
- Insert Some Temporal Documents
- Run some Search Queries on the Temporal Documents
Create Metadata Fields for the Valid and System Axes
The valid and system axis each make use of metadata fields that define the start and end times. For example, the following query creates the metadata fields to be used to store the valid and system axes.
JavaScript Example:
XQuery Example:
Create Range Field Indexes for the Valid and System Axes
The valid and system axis each make use of dateTime
range field indexes that define the start and end times. For example, the following query creates the field range indexes to be used to create the valid and system axes.
JavaScript Example:
XQuery Example:
Create System and Valid Axes
On the Documents database, create two axes, named valid and system, each to serve as a container for a named pair of field range indexes.
JavaScript Example:
XQuery Example:
Create a Temporal Collection
Create a temporal collection, named kool, that uses the previously created system and valid axes.
JavaScript Example:
XQuery Example:
Important:
Axis and temporal collection names are case-sensitive.
Insert Some Temporal Documents
Insert some documents into the temporal collection. In this example, a stock trader, John, places an order to buy some stock. The record of the trade is stored as a bi-temporal document, as follows:
-
The stock of KoolCo is trading around $12.65. John places a limit order to buy 100 shares of the stock for $12 at 11:00:00 on 3-Apr-2014 (this is the valid start time). The document for the transaction is recorded in the broker's database at 11:00:01 on 3-Apr-2014 (this is the system start time).
JavaScript Example:
XQuery Example:
Important:
You can usexdmp.documentGetMetadata
to display the metadata for a temporal document. For example:xdmp.documentGetMetadata("koolorder.json")
-
At 11:30:00, John changes his order to buy the stock at $13. The change is recorded as another version in the broker's database at 11:30:01.
JavaScript Example:
XQuery Example:
The result should be three documents with valid and system times as shown in the graphic below. Note that the second query resulted in a split on the Original document that resulted in a split document, as well as Version 2 that contains the new content.
Run some Search Queries on the Temporal Documents
The following query searches the temporal documents, using the cts:period-range-query
function to locate the documents that were in the database between 11:10 and 11:15. ISO_CONTAINS
is one of the comparison operators described in ISO SQL 2011 Operators.
In this example, only the Original Document meets the search criteria.
JavaScript Example:
XQuery Example:
The following query searches the temporal documents, using the cts:period-range-query
function to locate the documents that have a valid time period that starts after 10:30 and ends at 11:30. ALN_FINISHES
is one of the comparison operators described in Allen Operators.
In this example, only the Split document meets the search criteria.
JavaScript Example:
XQuery Example:
The following query searches the temporal documents, using the cts:period-range-query
function to locate the documents that were in the database after 11:20. ALN_AFTER
is one of the comparison operators described in Allen Operators.
In this example, both the Split and Version 2 documents meet the search criteria.
JavaScript Example:
XQuery Example:
The following query searches the temporal documents, using the cts:period-compare-query
function to locate the documents that were in the database when the valid time period is within the system time period. ISO_CONTAINS
is one of the comparison operators described in ISO SQL 2011 Operators.
In this example, only Version 2 meets the search criteria.
JavaScript Example:
XQuery Example:
The following query uses the cts:and-query
to AND two cts:collection-query
functions to return the temporal document that is in the URI collection, koolorder.xml
, and the latest
collection.
In this example, Ver2 meets the search criteria.
JavaScript Example:
XQuery Example: