How can you connect to MongoDB using Meteor?
Scenario A: Use the default embedded database
This is much simpler than what you did. When you start meteor , you actually start the database with the Meteor server, where Meteor listens on port 3000 and the database on port 3001. The Meteor application is already connected to this database on port 3001 and uses db called meteor . No need to return to MongoInternals.RemoteCollectionDriver . Just delete this code and change it to:
Boxes = new Mongo.Collection("boxes"); // use default MongoDB connection
Scenario B: Use a different default database
Using the MONGO_URL environment MONGO_URL , you can set the connection string in MongoDB when starting the Meteor server. Instead of a local database 3001 or an unauthenticated connection, you can specify exactly where and how to connect. Launch your Meteor server as follows:
$ MONGO_URL=mongodb://user: password@localhost :27017/meteor meteor
You can also leave the user: password@ command if authentication is not required.
Scenario C: connect to the second (3rd, etc.) database from the same Meteor application
Now we need to use MongoInternals.RemoteCollectionDriver . If you want to use a different database that is not the base database defined when the Meteor server starts, you should use your approach.
var database = new MongoInternals.RemoteCollectionDriver('mongodb://user: password@localhost :27017/meteor'); var numberOfDocs = database.open('boxes').find().count();
Bonus: why you should not use MongoInternals with Mongo.Collection ?
As the docs indicate , you should not pass any Mongo connection to the new Mongo.Collection() command, but only a connection to another Meteor instance. This means that if you use DDP.connect to connect to another server, you can use your code, but you should not mix MongoInternals with Mongo.Collection - they work poorly together.