Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Meteor.js, how would I have two development projects use the same Mongo instance?

Tags:

mongodb

meteor

I would like to have two separate applications use the same Mongo DB instance, and since I am developing them at the same time I would like to be able to share the same development DB instance.

I realize that each instance of Meteor would have to run on it's own port. Is there a way to force meteor or mrt to connect to a local socket like the system version of MongoDB?

like image 214
MrMowgli Avatar asked May 07 '14 22:05

MrMowgli


People also ask

What is a Mongo instance?

For a sharded cluster, the mongos instances provide the interface between the client applications and the sharded cluster. The mongos instances route queries and write operations to the shards. From the perspective of the application, a mongos instance behaves identically to any other MongoDB instance.

How do I access meteor MongoDB?

Open a terminal window and run meteor command. It will start running on localhost:3000 if you have not changed to port. Go to Robomongo (or your favorite mongodb client software) and create a new connection, making sure to change the connection address to localhost and the given the port number.


2 Answers

Yeah, you can just start meteor with the MONGO_URL parameter like:

$ MONGO_URL="mongodb://localhost:27017/myapp" meteor

or

$ MONGO_URL="mongodb://localhost:27017/myapp" meteor --port 4000

This assumes you have mongodb installed on your system. See this question for ways to make this process a little easier by using environment variables or a start script.

like image 54
David Weldon Avatar answered Sep 28 '22 07:09

David Weldon


David's answer is in the right direction, but threw me off a little. Instead, we're doing this to start the first app as normal:

$ meteor

Then to start the second app and connect to the database of the first, we're doing:

$ MONGO_URL="mongodb://localhost:3001/meteor" meteor --port 3002

The key here is that meteor starts its own mongo instance on port 3001, and we can connect to that directly from a second meteor instance. David's answer uses your system's mongo for both apps.

like image 42
chmac Avatar answered Sep 28 '22 05:09

chmac