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!
Related
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.
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.
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.
For production why should I "bundle" the meteor application and not just copy
the sources on the server use the "meteor" command?
Basically what is the difference between:
"meteor bundle app.tar.gz", then installing the right version of fibers and nodejs
and extracting the archive and starting with "node main.js" the app,
and copying the project sources on the server and just writing "meteor" to start
the app?
This won't be an exhaustive list, but here are some things that the meteor command does:
creates a local database
watches on every dependent file in your app or in your packages
sends every file separately and unminified to the client (this is super inefficient unless you are developing locally)
In contrast, bundling an app:
does not create a local database
does not spend CPU watching your files for changes
creates two minified files (js and css) which is perfect for putting on a CDN or hosting from a reverse proxy. These are also efficient for clients to download and are highly cacheable.
In general, deploying shouldn't be a huge pain if you use a good set of scripts.
When using a bundle:
It will not spawn meteor-mongo(Mongodb inside meteor)
No hot reloads
Meteor will not watch your files.
You can leave/quit the server without killing your app.
You can manage node processes smoothly by using pm2 or other similar npm packages.
You can decide where to put your mongoDB and decide what port to use.
You can connect to your mongodb remotely by not having to run your meteor app.
While using a copy or running meteor command in the project directory:
You can't leave/quit the server while keeping the project running without using any screen multiplexers (e.g. tmux)
You can only use meteor's assigned mongodb which is spawned in localhost:3001 -- if meteor is using port 3000.
You are letting meteor to watch over file changes which uses CPU.
When your app dies, your db dies. :)
I wanted to know how to go about getting a MongoHQ db to work on my localhost installation of Meter.
i tried using the settings.json method or the MONGO_URL=mongodb://user:pass#xxxx.mongohq.com:10061/xxxx when firing up meteor but both dont work and are probably the wrong way of doing it.
run it like this in your terminal within your project directory
MONGO_URL=mongodb://user:pass#xxxx.mongohq.com:10061/xxxx meteor
or
export MONGO_URL=mongodb://user:pass#xxxx.mongohq.com:10061/xxxx
meteor