Hi there,
I am trying to figure out how I can connect my Meteor application to an external MongoDB.
I’m very new to Meteor and am more of a Firebase person so please bear with me.
So far I have tried the following:
Upon running my application locally I run the following command…
MONGO_URL="<My Mongo URL Here>" meteor
… And within my application I had the following client side code…
Demo = new Mongo.Collection('demo');
This failed to create the collection in my specified MongoDB URL. Rather, I believe, it just created it in Meteor’s mini mongo?
So I then tried deploying the application to Meteor and pointed the application to my settings.json file which looks like so…
{
"galaxy.meteor.com": {
"env": {
"MONGO_URL": "<My Mongo URL Here>"
}
}
}
… And again upon running the application it fails to create the collection in my specified MongoDB.
So I turned my attention to a question found here…
https://forums.meteor.com/t/how-to-view-collection-contents-using-console-log/?source_topic_id=37984… And I have attempted to do a similar thing with subscribe and publish.
I created a folder called server and within it a file called main.js which contained the following:
const Tasks = new Mongo.Collection('tasks');
Tasks.insert({_id: 'my-todo'});
if (Meteor.isServer) {
// This code only runs on the server
Meteor.publish('tasks', function() {
return Tasks.find();
});
}
Within my application on the client side I added the following code to my JS file:
if (Meteor.isClient) {
Meteor.subscribe('tasks');
}
According to the help forum this should work - I think… I’m not sure:\
It works partially - The tasks collection is created in my specified Mongo URL and the task is inserted into it.
However, I don’t know how to display this now on the client side.
Does any body know how I now display this data into my application?
Many thanks,
G