Trouble setting up MongoDB

Jon_Young @Jon_Young: hey there. I’m trying to get a mongodb instance set up using the render mongodb docs. Here’s what I’ve done so far:

  1. created an admin user for the db
  2. updated etc/mongod.conf.orig to enable auth and allow network interfaces other than just localhost
  3. redeployed the web service by clearing build cache & redeploy. I wasn’t sure how to restart mongod via the dashboard shell, but a new build felt like it might do the trick :mage:
  4. reconnected to mongo in the web service’s shell and found both the admin user I created and the edits to the config file I made were lost :confused:

A few questions:

  1. Why didn’t the user I created persist across builds? Same goes for the changes I made to the mongd.conf.orig file.
  2. How do I know my data won’t be lost if I ever need to rebuild my service — for example, in the case of a DB version upgrade?
  3. Do I handle db config in the Dockerfile provided in the template repo? (I’m not familiar with Docker). Most Docker resources I’ve found want me to configure mongo in a docker-compose.yml file, but that doesn’t seem like the right fit here since this web service is for mongodb only, not multiple containers?
    Any resources would be helpful here!

Hi Jon, responses inline:

  1. Why didn’t the user I created persist across builds? Same goes for the changes I made to the mongd.conf.orig file.

This sounds to me like the data files and mongd.conf.orig are not on a persistent disk. In the doc you linked, one step is to add a disk and mount it at /data/db. Did you do that?

  1. How do I know my data won’t be lost if I ever need to rebuild my service — for example, in the case of a DB version upgrade?

If the data is stored on the persistent disk mentioned above, it will persist across new versions of your service. Render also takes regular snapshots of your disks, so you can restore from a previous snapshot when necessary. See our docs on Disks for more detail.

  1. Do I handle db config in the Dockerfile provided in the template repo? (I’m not familiar with Docker). Most Docker resources I’ve found want me to configure mongo in a docker-compose.yml file, but that doesn’t seem like the right fit here since this web service is for mongodb only, not multiple containers?

Render doesn’t support docker-compose.yml. If you create a Docker service, you need to provide a single Dockerfile. If you want multiple containers, you can coordinate that by using our Infrastructure as Code.

If you want to provide extra configuration at build-time, you can fork the example repository and add more steps to the Dockerfile.

Thanks for these answers, @dan.

This sounds to me like the data files and mongd.conf.orig are not on a persistent disk. In the doc you linked, one step is to add a disk and mount it at /data/db . Did you do that?

I did not add a disk. I assumed that was handled by this render.yaml file included in the template:

services:
  - type: pserv
    name: mongodb
    env: docker
    disk:
      name: data
      mountPath: /data/db
      sizeGB: 10

If this doesn’t control the persistent disk, what is the purpose of this file?

If you want to provide extra configuration at build-time, you can fork the example repository and add more steps to the Dockerfile.

Just to be crystal clear: Is the Dockerfile where I want to write the mongodb config? Or once I add a persistent disk, should I do this in mongo.conf.orig?

If I’m supposed to use the Dockerfile, could you point me to a resource that details what that file might look like for a basic mongodb config?

Thanks, Jon

If this doesn’t control the persistent disk, what is the purpose of this file?

The disk section does create the disk, so if you used that render.yaml then your service will correctly have a persistent disk.

Just to be crystal clear: Is the Dockerfile where I want to write the mongodb config? Or once I add a persistent disk, should I do this in mongo.conf.orig ?

Your persistent disk is mounted at /data/db, so any file changes you make outside of that directory during runtime will not be persisted. On the other hand, your Dockerfile is executed during the build step, and is used to produce your service’s base image, so any writes you perform will be saved as part of that base image.

Mongo’s configuration file, by default, lives at /etc/mongod.conf, which means you will need to write to it at build time using your Dockerfile. The Dockerfile RUN command is something you can use to write the file.

If I’m supposed to use the Dockerfile , could you point me to a resource that details what that file might look like for a basic mongodb config?

I’m not personally familiar with mongo configuration, but their Configuration File Options doc has a lot of great information.

Cheers,
Dan