Local development with remote database hosted by meteor.com - meteor

I develop Meteor application on my local computer, and deploy it to meteor.com. I want to have an opportunity to use remote production MongoDB database for local development.
So, I get url to my DB with meteor mongo --url myapp.meteor.com, then I add it to my MONGO_URL environment variable:
export MONGO_URL=mongodb://client-5345a08c:5f63edff-8cec-a818-7f35-c05021bb6d91#production-db-d1.meteor.io:27017/34377_ru
The inconvinience is that this url is invalid in one minute, so I need to generate another one and modify my MONGO_URL every time I want to start my application. I suspect some permanent url to my MongoDB is out there. I ran meteor mongo myapp.meteor.com and noticed greeting:
MongoDB shell version: 2.4.9
connecting to: production-db-d1.meteor.io:27017/34377_ru
I tried to use this url:
export MONGO_URL=mongodb://production-db-d1.meteor.io:27017/34377_ru
and even
export MONGO_URL=mongodb://myneteorcomusername:mymeteorcompassproduction-db-d1.meteor.io:27017/34377_ru
but I had no luck.
Are there ways to simplify my workflow and make meteor use my remote database by default?

I guess for scaling purposes, there is no dedicated mongo ever for each subdomain. I could be wrong so better ask this question over at the Meteor Talk Google group.

Related

Bluemix/CloudFoundry + Meteor - How to Project Reset?

When developing with Meteor locally, one execute meteor reset locally to refresh the database.
Can one run this command on a production level app deployed on Bluemix without digging into the Mongo console?
The meteor reset command actually deletes the local mongo database files in .meteor/local. Since the database isn't stored in the application container when running in Cloud Foundry, there isn't an equivalent operation as a one liner.
Seems like your only option is to retrieve the connection credentials from your application cf env appname and then stop the application, connect with the mongo command line, and use one of the methods described in this answer to clean your data out.

How to reset a meteor project thats been deployed with meteor up

I have used meteorUp here sucesffuly to deploy my meteor project on my own host.
However I have no idea how to reset the database, or the entire project itself, like I can locally with the simple meteor reset command. I tried installing meteor on the server but there is no .meteor project so that command doesnt work. I looked in /opt/meteor folder but no meteor project exists.
If you need to reset the data. You need to login to the server. login to mongodb with mongo meteor.
Then do db.dropDatabase() to delete the DB.
If you need to change the app, simple redeploy should work.
BTW: Do you not use MongoDB this way for a production app.
If you are using mup or mupx try:
Login to your server:
$ ssh <user>#<server-ip>
Login into mongo shell
$ docker exec -it mongodb mongo <app-name>
Drop db
> db.dropDatabase()
Is this what you are looking for?
mup reconfig
Based on the doc for it:
This will also restart the app [without re-deploying], so you can use it for that purpose
even if you didn't change the configuration file.
I don't have enough points to comment yet, but to add onto Arunoda's response, you might want to
use [name of app database]
before you
db.dropDatabase()
And if you don't know what the name is you can also
show databases
If you used mup, the database will generally be the same name as your app.

Permanently configure Meteor development MongoDB url

I am trying a test to move all my development to Nitrous.io IDE, but with limited space in my Nitrous box I want to permanently host my Mongo databases at MongoHQ.com. Currently each day I need to set my MONGO_URL by running:
export MONGO_URL='mongodb://<user>:<pass>#paulo.mongohq.com:12345/<db>'
If I fire up another console or logout of Nitrous my MONGO_URL needs to set again.
How can I set the development MONGO_URL for good per meteor app? I cannot find a config file anywhere.
Nitrous support helped me find a quick solution. Just wanted to answer it here for others with the same issue.
Open ~/.bash_profile and enter your DB information.
example:
export MONGO_URL='mongodb://jimmy:criket#paulo.mongohq.com:12345/mynitrobox'
Next in the console run source ~/.bash_profile to load the settings.
This sets the DB for your entire node.js box, not individual meteor apps, so you may want to structure your Mongo collections accordingly with subcollections.
you can do this in one line like so:
MONGO_URL='mongodb://<user>:<pass>#paulo.mongohq.com:12345/<db>' meteor
I don't know much about Nitrous.io but in AWS EC2 I have an upstart job that runs this for me when the server starts.
I gist'd my approach a while back, I've since changed it a bit but this still works:
https://gist.github.com/davidworkman9/6466734
I don't know that this will help you in Nitrous.io though, good luck!

Meteor deploy erase public folder

on meteor i've just added a new feature to download some image in public/img/aSpecificFolder.
It works locally, but i've seen that each time i deploy on meteor.com using deploy command, it looks like that public folder is completely erased. Or maybe that the deploy remove the current app and install a new one. So it only keept the connection to db but all files are removed and put again.
What is the good way of doing if i want to store image on meteor.com ?
thanks
Have you considered using something like collections-fs. When you deploy on meteor it will clear your previous app and use the new one.
If you use something like collections-fs it lets you store your files in the mongo database instead, so they're not actually on the same server that serves out data.
This is also good in another way (scaling) since each virtual environment that hosts your app is able to access the files. If you store the files statically they will only be accessible on one of the servers.
For the moment meteor hosting (via meteor deploy) uses one server, but its likely it will be scalabale in future.

How do I use an existing MongoDB in a Meteor project?

Let's say there is a running MongoDB server for a GUI client (by wxPython) for a while.
How could I connect my new Meteor project to my already existing MongoDB?
Use the environment variable MONGO_URL.
Something like:
export MONGO_URL=mongodb://localhost:27017/your_db
Replace your_db with meteor or whatever db you want to use.
We use npm:
Create a package.json file with npm init, if you don't have one already.
Enter and modify the following line in that file (replacing all the <...>'s):
"scripts": {"meteor": "MONGO_URL=mongodb://<USER>:<PASSWORD>#<SERVER>:<PORT>/<DB> meteor"}
You can then start meteor with just npm run meteor
In the comments to danny's answer Tom Wijsman recommends patching packages/mongo-livedata/mongo_driver.js, line 21. A better place is in app/meteor/run.js, line 460. This way the environment variable is still picked up if present, such as when running Meteor on Heroku. Just change the default hardcoded mongodb://127.0.0.1 to the location of your MongoDB server.
You can use db.copyDatabase to do this, with a caveat that there is a bug and you can't update the data in Meteor. See https://github.com/meteor/meteor/issues/61
If you're using the development version of Meteor, you can transfer data from a running MongoDB server by starting your Meteor app, then doing:
mongo --port 3002
This will connect you to the Meteor app's Mongo server. Now use db.copyDatabase like this:
db.copyDatabase('myappDatabase', 'meteor', 'localhost');
This will copy the database myappDatabase from a MongoDB server running on the standard port on localhost, to the Meteor app Mongo server. The database name the Meteor app uses is 'meteor'.
Just copy the data to the Meteor MongoDB database - no reason to try to hook Meteor up to the existing database and risk overwriting things.
Use mongoexport to dump your collections individually, then mongoimport to import the files into the database named meteor in the Meteor MongoDB instance. The Meteor MongoDB instance runs on port 3002 with bind_address 127.0.0.1, and the data files are in the Meteor project subdirectory .meteor/local/db.
See the documentation if you're not familiar with import/export in MongoDB.
All I did was add the IP of my Digital ocean droplet server, instead of localhost, and it worked:
env: {
ROOT_URL: 'http://yourdomain.com',
MONGO_URL: 'mongodb://104.236.24.66:27017/meteor',
PORT: 3002,
},
EDIT:
use MUP to deploy your meteor projects: https://github.com/zodern/meteor-up
env: {
ROOT_URL: 'https://www.example.com',
MONGO_URL: 'mongodb://localhost/meteor',
},
Mup uses Docker, and will "link" your 2 containers, thus hosting both the app and mongo on the same VM (server). Your mongoDB shouldn't be accessible from the public IP for security reasons.
Spent a lot of time and found out that it requires quotes around the URL:
export MONGO_URL='mongodb://localhost/meteor'
export MONGO_OPLOG_URL='op log url'
You have to keep your app running in one terminal window then open another and type "meteor mongo" and it should work!

Resources