Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to a remote MongoDB using Meteor

Tags:

mongodb

meteor

Apologies in advance for any failing with my terminology and understanding with Meteor/Mongo, I've just started learning and developing with it.

I am trying to connect my local meteor app to a remote mongodb which is hosted elsewhere.

My code looks like this:

Bills = new Mongo.Collection("bills");
 if (Meteor.isClient) {
  Meteor.subscribe("bills");
  // This code only runs on the client
  Template.body.helpers({
    documentContent: function () {
      return Bills.find();
    }
  });

  Template.documentBody.helpers({
    documentContent: function () 
      {
        var thingy = Bills.find();
        console.log(thingy);
        return Bills.find({_id: "784576346gf874"});
      }
  });
}

I have connected to the DB via the shell using the following:

$ MONGO_URL="mongodb://mysite.net:27017/legislation" meteor

In my browser I receive no errors and within my defined template I see [object Object]. The console shows a local miniCollection but doesn't return any of my documents from the subscribed collection.

I guess what I am asking is; if you were connecting to a remote MongoDB within your local app, how would you do it?

Thank you for taking the time to read, any helps is massively appreciated.

like image 571
T-Rex Tam Avatar asked Nov 25 '14 11:11

T-Rex Tam


1 Answers

Rex, If you're not seeing errors in the output on the browser, or in the console where you're running the server then you may be setup ok. That's exactly how I'm doing it.

Run meteor list in server directory and look for insecure and autopublish

You should understand these two packages They are for rapid prototyping. If they are present, then keep digging into MongoDB and the connection.

I recommend Robomongo for viewing documents directly in MongoDB.

If they are absent, then you need to go about publishing data (getting it from the server to the client) and securing it (letting clients only modify their data).

I recommend these two packages for that.

reywood:publish-composite ongoworks:security

If you haven't read an introduction to meteor book, it's really worth the time. I've been developing for some time and learned meteor recently. It was invaluable.

like image 196
Michael Cole Avatar answered Oct 04 '22 22:10

Michael Cole