Accessing data from an external MongoDB collection

I’m new to Meteor and am just using it as part of my University work experience.

I’m trying to run my application locally but connecting to an external MongoDB not the default meteor mongo.
I’m connecting to this external database by navigating to my project directory and typing:

SET MONGO_URL=“mongodb://Name:Password@******,******,************-shard-0&authSource=admin”

(Obviously with the relevant details filled in)

And typing “meteor”.

This seems to work fine, although there is no sort of confirmation that a connection is successful or even attempted to be made.
But my question is what do I have to do within my meteor project to actually call for some data to be displayed from this external database - All the tutorials I watch only show how to call from the default local MongoDB.

For example, using the Mongo shell I can see that I have 3 databases - “Admin”, “Local” and “Names”.
Within the names database I have a collection called “NamesList” which contains an array of random names.
What do I have to do within my meteor app to display and list that “NamesList” collection?

Apologies if this is a really dumb question but I seem to be going round in circles myself so could really do with a bit of advice!

Thank you!

Your MONGO_URL does not specify which database to connect to. I presume you want to access the Names database and the collections therein? Specify the DB in the MONGO_URL. Also specify access to local in a separate variable MONGO_OPLOG_URL (in my case credentials for the DB and local are different)

SET MONGO_URL="mongodb://Name:Password@***********"
SET MONGO_OPLOG_URL="mongodb://Name:Password@************-shard-0&authSource=admin"

Thanks for your help - Missed that bit!

Any idea how I would display the contents of the names database? Basically just a blank app which just lists the items within the collection of names?

I suggest reading the documentation or any one of many tutorials out there.

Besides the actual connection it is very easy to use an existing external mongo database. Just keep in mind that meteors idGeneration is different. Meteor uses rabdom strings as opposed to mongo’s default ObjectId. You can read about it on the meteor docs:

1 Like