Question

Does anybody have specifics on how to connect an Android application to MongoDB running on Azure roles?

--

Hi, I have MongoDB replica set running on multiple Azure roles in the Cloud Service. I have used the mongo-azure library on GitHub to create the role instances and have them running in Azure.

Most articles online seem to only talk about connecting to Azure-MongoDB locally (via localhost). But, since my application won't be running locally to Azure, I feel that I have to use REST to somehow connect to Azure cloud servers, which may or may not propagate data to the MongoDB replica set.

Does anybody have more specifics on how to connect an Android application to MongoDB running on Azure roles?

(Or, for those that don't have experience with Android/Java: how to connect from non-localhost using non-.NET?)

ps - In other MongoDB questions, people have already answered Android is not natively support by MongoDB, and using non-native methods is fine by me. There are apps out there that already do this, mainly Foursquare. Unfortunately, they use AWS instead of Azure (the requirement for me).

pps - if anybody has any more resources for the linked mongo-library about how it works in more detailed terms, then that would be very helpful too.

UPDATE:

  • I found the most up-to-date version of mongo-java-driver.jar (currently 2.11.3) and am testing that.
  • Thanks to another question I've found the particular issue with Android not supported by the java driver, but that issue appears to be resolved.

Possible Solution:

  • In the Visual Studio project, I created an Input Endpoint for the role. So far that seems to do the trick, using MongoClient mongo = new MongoClient("<my_ip_address>", 27017);
Was it helpful?

Solution

Your 'possible solution' is the right one in my view - you need to open a (load balanced) TCP port in the firewall surrounding your roles and InputEndpoint is the way to do that.

OTHER TIPS

You cannot use an input endpoint if you are doing writes when using a replica set of size > 1 if you are the github solution above. You do not want the Azure load balancer to route a write (insert or update) to a secondary of MongoDB in which case your write will fail. If you use Azure virtual machines then you can create a port mapping per virtual machine instance and overcome this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top