> For the complete documentation index, see [llms.txt](https://docs.xibosignage.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.xibosignage.com/cms-configuration-and-integration/using-mongodb-to-store-proof-of-play-and-other-time-series-data.md).

# Using MongoDB to store Proof of Play and other time series data.

MongoDB is enabled via the `settings.php` file in the CMS installation. If Docker has been used `settings.php` will not be accessible, however, it is possible to create a `settings-custom.php` file in the `/custom` mount point. The below **Configuration** can be added to that file instead.

## Configuration

Please ensure you have Xibo version 2.1.0 or later before enabling MongoDB. You will also need to have a working MongoDB instance with a user and database created.

Add a new variable called `$timeSeriesStore` to your settings file. The variable should be a function which returns a `\Xibo\Storage\MongoDbTimeSeriesStore` created with your MongoDB connection details.

```php
$timeSeriesStore = function() {
    return new \Xibo\Storage\MongoDbTimeSeriesStore([
        'host' => 'mongo',
        'port' => '1234',
        'database' => 'db_name',
        'username' => 'user',
        'password' => 'password'
    ]);
};
```

## Mongo Indexes

We recommend adding an index to the `stat` collection in your MongoDB database. To do this from the console, make sure you have your database selected and then:

```
db.stat.ensureIndex({ "start": -1, "end" : -1, "type": 1}, {background: true})
```

## Migrating

Unless your CMS is a brand new installation you will likely have existing proof of play data which you want to move into MongoDB in a controlled fashion.

Xibo provides a migration task to achieve this which can be enabled by clicking on **Tasks** under the **Administration** section of the main CMS menu.

We have provided a set of default options for the task which you may want to adjust according to your environment. The default options intend to provide a slow and steady migration of your existing data.

#### Available options:

* killSwitch (0 or 1 to completely disable processing)
* numberOfRecords (how many to process each time)
* numberOfLoops (how many loops to do per task run)
* pauseBetweenLoops (how long to wait between each loop)
* optimiseOnComplete (issue an OPTIMIZE TABLE stat after truncating)
* configOverride (an optional path to a JSON file containing overrides for all of the above settings)

If you already use the StatsArchiver task it will be disabled during migration to prevent conflicts.

Nothing will be deleted from the `stat` table in the MySQL database until the migration has completed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.xibosignage.com/cms-configuration-and-integration/using-mongodb-to-store-proof-of-play-and-other-time-series-data.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
