# Clean up the Data Watcher MongoDB

To clean up the Data Watcher DB launch the mongodb-cleaner.sh script, stored at:\
`$DATAWATCHER_HOME/dweventscollection/maintenance`

Usage:

`./mongodb-cleaner.sh [ last=10 | to=30/06/2025] [ queryFilter="<DWQL query>" ]`

`./mongodb-cleaner.sh [ status | stop ]`&#x20;

Note that last and to, status and stop are exclusive.&#x20;

Where:

* last=n\
  The cleaner will delete all data older than the number of days entered.\
  Example:\
  `./mongodb-cleaner.sh last=10`\
  will delete all data that is 11 days or older.
* to=DD/MM/YYYY\
  The cleaner will delete all data up to a specific date.\
  Example:\
  `./mongodb-cleaner.sh to=30/06/2025`\
  will delete all data up to 30th June, 2025. Data from 1st July, 2025 to the current date will be kept.
* queryFilter:\
  The cleaner will delete flows specified according to the Data Watcher Query Language literals. See the [How to run searches in Data Watcher](/data-watcher-1.21/troubleshooting/how-to-run-searches-in-data-watcher.md) page. The cleaner will act on the subset of flows identified by the specified query. Multiple values can be separated by OR and/or AND. If nothing is specified, AND will be applied. \
  Example:\
  `./mongodb-cleaner.sh last=0 queryFilter="Nasa[source] projects_Jan_2022[entity]"`\
  will clean all flows sent from Nasa with filenames projects\_Jan\_2022.\
  Note that the searchscope (the attribute in square brackets) **must be present** or an error will occur. I.e., entering queryFilter="Nasa\[source] projects\_Jan\_2022" is not correct.&#x20;
* status:\
  It prints if the cleaner is running or not.\
  Example:\
  `./mongodb-cleaner.sh status` &#x20;
* stop:\
  It stops the cleaner - if running\
  Example:\
  `./mongodb-cleaner.sh stop` &#x20;
* exit codes:\
  0: execution terminated successfully\
  1: execution failed

Logs:\
The cleaner logs information at this path:\
`$DATAWATCHER_HOME/dweventscollection/logs/mongodb-cleaner.log`.\
The history of the latest 4 cleanup procedures are saved.


---

# Agent Instructions: 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:

```
GET https://docs.primeur.com/data-watcher-1.21/troubleshooting/data-watcher-mongodb-scripts/clean-up-the-data-watcher-mongodb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
