# MongoDB

## Reference Links

## Configuration

## Docker

### Image

{% embed url="<https://hub.docker.com/_/mongo>" %}

### Compose

```yaml
version: "3.7"
services:
  mongo: # access with `mongosh 'mongodb://user:password@127.0.0.1/database?authSource=admin'`
    # image reference: https://hub.docker.com/_/mongo
    image: library/mongo:6.0.8
    environment:
      MONGO_INITDB_DATABASE: database
      MONGO_INITDB_ROOT_USERNAME: user
      MONGO_INITDB_ROOT_PASSWORD: password
    ports: ["27017:27017"]
    network_mode: host
    volumes: # [] # uncomment this and comment below to remove persistence
      - ./.data/mongodb/data/data/db:/data/db
```

## Debugging/error handling

### Useful links

* [Official MongoDB documentation on exit codes and statuses](https://www.mongodb.com/docs/manual/reference/exit-codes/)

### Exit code 14

#### Keywords

"FileNotOpen", "Failed to open archive file"

#### Explanation

This exit code is formally defined as:

{% code overflow="wrap" %}

```

Returned by MongoDB applications which encounter an unrecoverable error, an uncaught exception or uncaught signal. The system exits without performing a clean shutdown.
```

{% endcode %}

**Exploration**

This error typically implies a system-level issue that prevents MongoDB from starting successfully.

**Known Fixes 1 - MongoDB by Bitnami running in Kubernetes**

This fix addresses an issue where the disk space allocated for MongoDB was filled to 100%

* Update the `statefulset` resource so that the container's `command` is `sleep 1000000`.
* Allow the MongoDB `pod` instances to restart
* Get a shell into each of them and use `df -h` to view the available diskspace
* Observe that `/bitnami/mongodb` is at 100% or near that
* Using MongoDB logs, figure out where it is trying to write to, in this fix, the issue was with the diagnostic data and the following command was run to free up disk space:

```
rm -rf /bitnami/mongodb/data/db/diagnostic.data/*
```

**Reference/useful links**

* <https://stackoverflow.com/questions/68067064/mongodb-failed-to-start-due-to-filenotopen>
*


---

# 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://notes.joeir.net/application-infrastructure/databases/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.
