Create new database in mongodb with docker-compose

Here’s what the description of the mongo image spells out:

Initializing a fresh instance

When a container is started for the first time it will execute files with extensions .sh and .js that are found in /docker-entrypoint-initdb.d . Files will be executed in alphabetical order. .js files will be executed by mongo using the database specified by the MONGO_INITDB_DATABASE variable, if it is present, or test otherwise. You may also switch databases within the .js script.

You may want to try setting MONGO_INITDB_DATABASE.