1

I have a meteor app in which I am using a mongoDB ObjC driver to write to it from an ios app. This works fine when the meteor app is running locally (port 3000). I simply use dbConn = [MongoConnection connectionForServer:@"127.0.0.1:3002" error:&error]; The problem is once I deploy the app to meteor.com. I can find the ip address by using ping whatever.meteor.com but where do I go from there. I don't know how to write to the deployed mongoDB. It should be fairly simple, but I can't seem to figure it out. Thanks.

Nate
  • 1,875
  • 15
  • 27
  • You would need to change the host IP to reflect the server that is hosting your MongoDB node. It will be something other than 127.0.0.1 (localhost). Also, you should verify if authentication is turned off or on. If on, then you will need credentials (username and password). – Rishi Feb 11 '14 at 21:00
  • @Rishi I can find the ip address using `ping whatever.meteor.com` in terminal, but it's not still port :3002 is it? – Nate Feb 11 '14 at 21:03
  • hard to say, but probably not. Did you try port 27017 (Mongo's default server port). – Rishi Feb 11 '14 at 21:04
  • @Rishi yeah I did try that port. How do I test if authentication is turned off or on. I do not have the insecure package. Is that what you mean? – Nate Feb 11 '14 at 21:12
  • 1
    You need to obtain a username, password and the associated db name. Once you have that you can connect using a connection string like: "mongodb://:@whatever.meteor.com:27017/" – Rishi Feb 11 '14 at 21:21
  • @Rishi thanks. I have also looked at [link](http://docs.mongodb.org/manual/reference/connection-string/) which complements what you are saying. Can I test the string to see if it works using the shell? – Nate Feb 11 '14 at 21:52
  • 2
    Surely, in the shell you can test connection using: `$ mongo whatever.meteor.com:27017/ -u -p ` – Rishi Feb 11 '14 at 21:54
  • @Rishi using meteor the command it `$ meteor mongo whatever.meteor.com:27017` which allow for the use of looking at collections `db.collection.find()`. However I still can't get the driver to connect, using a similar string. – Nate Feb 11 '14 at 22:49
  • 1
    You need to find out the username and password. `meteor mongo` probably is handling authentication for you, so it's not helping you do that. Try to connect using the mongo shell, as Rishi suggests. – paulmelnikow Feb 11 '14 at 23:07
  • ObjCMongoDB doesn't have auth support; see https://github.com/paulmelnikow/ObjCMongoDB/pull/4. I'll try to get that in; meanwhile you could try making ganglio's changes in your copy. – paulmelnikow Feb 11 '14 at 23:08
  • 1
    Sort of an aside: the Mongo wire protocol is unencrypted, so generally I would advise against this particular architecture… I think even the password is sent in the clear. – paulmelnikow Feb 11 '14 at 23:11
  • @noa great thanks for the response. I will try to get it working. Also good to known about the unencryption. That might become an issue later in development but for right now I'm not too worried about it. – Nate Feb 11 '14 at 23:16

1 Answers1

1

To get temporary mongodb credentials run this command:

meteor mongo whatever.meteor.com --url

Source: https://stackoverflow.com/a/17009756/219238

Note that the credentials will only be valid for 1 minute so the proper way to save data from your ObjectiveC client is to have it communicate with the meteor webserver instead of directly with mongodb. The simplest way to do this is to expose a REST endpoint using the iron-router package as outlined here: https://github.com/EventedMind/iron-router/#server-side-routing

Community
  • 1
  • 1
alanning
  • 5,198
  • 2
  • 34
  • 33
  • The command returns `mongodb://client-89674e99:60036738-de64-cde9-ecc1-b58abf778d44@production-db-c3.meteor.io:27017/whatever_meteor_com` which gives me the ability to communicate to the mongoDB for 1 min. Are my collections still called `meteor.collection` or just simply `collection`? – Nate Feb 13 '14 at 15:54
  • @Nate, this is controlled by the ObjC driver. Looking through the wiki, it looks like "mydb.collection": https://github.com/paulmelnikow/ObjCMongoDB/wiki/TheBasics#wiki-setting-up-the-database-connection – alanning Feb 13 '14 at 17:20
  • If I was to host my own server with my own mongodb, would the string still need to be refreshed every 1 minute? Or is that feature just a built in .meteor.com security feature? – Nate Feb 24 '14 at 16:41
  • 1
    @Nate, using an externally hosted mongodb avoids the 1 minute refresh. Based on Noa's comment, its still not secure to send data directly to mongo though. So externally hosted or not, you'll still want to have another service in between that can secure the messages. Once secure galaxy hosting is available you can do it right from your meteor app. You can actually do it now on meteor.com but I don't think you can use a custom domain and still get ssl in the current setup. – alanning Feb 25 '14 at 00:39
  • I do this, but then with using the given url, I get "not authorized for insert on meteor.db.myCollection." Anyone know what I'm doing wrong? – Dylan Reich Dec 22 '14 at 09:47