title: Creating mongodb database and populating it with some data via docker-compose
body: <p>I've the following script with a custom database specified but I don't see the database user getting created within the GUI (compass). I only see 3 default databases (admin, config, local).</p>
  
  <p>I've looked into this <a href="https://stackoverflow.com/questions/42912755/how-to-create-a-db-for-mongodb-container-on-start-up">linked</a> answer but I need a specific answer for my question, please. </p>
  
  <pre><code>mongo:
      image: mongo:4.0.10
      container_name: mongo
      restart: always
      environment:
        MONGO_INITDB_ROOT_USERNAME: root
        MONGO_INITDB_ROOT_PASSWORD: mypass
        MONGO_INITDB_DATABASE: mydb
      ports:
        - 27017:27017
        - 27018:27018
        - 27019:27019
  </code></pre>
  
  <ol>
  <li>The expectation for a user database to be created.</li>
  <li>Database prefilled with some records.</li>
  </ol>
  
  <hr>
  
  <p><strong>Edit - made some progress, 2 Problems</strong></p>
  
  <p>Added volumes</p>
  
  <pre><code>mongo:
    image: mongo:4.0.1r0
    container_name: mongo
    restart: always
    volumes:
      - ./assets:/docker-entrypoint-initdb.d/
  </code></pre>
  
  <p><strong>1. Ignore</strong></p>
  
  <p>Within assets folder, I've 3 files and I see this in the logs, my files are getting ignored.</p>
  
  <pre><code>/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/file1.json
  
  /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/file2.json
  
  /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/file3.json
  </code></pre>
  
  <p>all my JSON files look like following. (no root array object? no <code>[]</code> at the root?)</p>
  
  <pre><code>{ "_id" : { "$oid" : "5d3a9d423b881e4ca04ae8f0" }, "name" : "Human Resource" }
  { "_id" : { "$oid" : "5d3a9d483b881e4ca04ae8f1" }, "name" : "Sales" }
  </code></pre>
  
  <p><strong>2. Default Database not getting created.</strong> following line is not having any effect.</p>
  
  <pre><code>MONGO_INITDB_DATABASE: mydb
  </code></pre>