Accessing data on a remote device

Hi!

I’m working with an application that runs two services: one service runs MongoDB, the other one generates some data that is stored in the MongoDB database.

I’m working with the device remotely. That is, not on the same network as the device, and I wonder if you have some recommendations on how to access the data on the remote device in the Balena ecosystem? In other words, what is the “Balena” way of accessing data on a remote device?

Thanks! :smiley:

Hi,

In order to connect to remote mongob instance, you have to:

  1. Enable mongo authorization;
  2. Uncomment # bindIp: 127.0.0.1 line in mongod.conf file;
  3. Open port in docker-compose:
ports:
      - '27017:27017'
  1. Connect to <device_ip>:27017

See authorization instructions: https://ianlondon.github.io/blog/mongodb-auth/

Great, I’ll take a closer look at this!

One follow-up question regarding step 4. Connect to <device_ip>:27017. In this case, what do mean by the device ip? Since the device is on a different network, I cannot work with the device ip address given in the Balena dashboard. Or am I missing something?

Hi,

At the moment, you will only be able to access that port directly when you are on the same local network as the device. To expose that port externally, you will need to map port 80 to the mongoDB port:

ports:
      - '27017:27017'

Enable the public URL for the device:

And then use the device URL to access mongo.

Hope this helps,
Phil

1 Like

Thanks, Phil!

That gives me the answers I need at this stage. :smile: