How to persist mongodb when deploying with meteor? - mongodb

When I meteor deploy my app, it seems to create an entirely new mongodb instance. I'd like to be able to deploy with the current mongodb have locally.
Same goes the other way -- I'd like to be able to download the mongodb back to my localhost after it has been deployed.
For clarification, I'd really like to know the follow:
1) how to deploy with a fresh mongodb
2) how to deploy to an existing deployed app without overwriting the old mongodb
3) how to download/sync mongodb locally with the existing deployed app
4) how to make local backups of mongodb

You can perform a mongo dump using meteor mongo to export your local database and deploy your app using Meteor Up which should also allow you to automate the database import and deployment process.
"Meteor Up (mup for short) is a command line tool that allows you to deploy any meteor app into your own server."

You can stop the mongodb service and start a mongod instance in a separate terminal, by just typing mongod. This will let you monitor what's happening on the mongodb instance that you just started.
Open another terminal and do export MONGO_URL=mongodb://localhost:27017/nameOfDBgoesHere
This will create a new DB named "nameOfDBgoesHere" and it won't overwrite what you currently have, unless you name it with the same name.
After that just start meteor by typing meteor in your program's folder. In the mongod terminal that you opened you should see some connections opening.
By default mongodb creates it's DB files in /data/db. If you have another meteor app and follow the same steps in another terminal, while keeping the name of the DB you specified in the MONGO_URL you will just connect to it from that app - without overwriting anything.
As for the syncing with a deployed app and the local backups of mongo - it seems like something that the mongodb website covers, but maybe someone can chime in here. Not sure if there is a meteor specific, easy way of doing this.

Related

How to perform something like meteor reset on deployed app?

I have an app deployed on digital ocean and am trying to perform a meteor reset to reset the DB etc. Where is meteor located when deployed via mup? I keep getting a command not recognized with meteor commands.
As far as I know you can't run meteor reset on deployed apps like that as it's already been built by MUP. The way you could mimic a meteor reset is to run the mongo shell on your digital ocean server:
mongo
You can check what the databases are by using:
show dbs
and then access the one meteor is running by doing:
use [db name]
and then manually drop the databases by using:
db.[collection name].drop()
http://docs.mongodb.org/manual/reference/method/db.collection.drop/
Meteor already has the user collection defined so you'd probably want to drop that collection too if you want a clean start

Where to set mongodb start parameter in a meteor application on nitrous.io?

I'm studying meteor and trying some examples on nitrous.io, but the available disk space was soon consumed by the big mongo data files (including the prealloc journal files).
Unfortunately MongoDB is also new to me. I googled around and found that I can start mongoDB with some parameters like --nojournal, but I have no idea where in the nitrous.io app I can pass this parameter to mongodb at startup?
I also can't find any mongodb.conf (even *db.conf) to use the storage.smallFiles setting.
Any help would be appreciated!
Instead of using Meteor's builtin MongoDB instance, you can specify a custom instance (which you can configure the way you want).
To do this Nitrous.IO, you can follow these steps:
Create a box with Meteor template.
Install MongoDB, by running parts install mongodb (Autoparts is Nitrous.IO specific package manager)
Open the MongoDB config located at /home/action/.parts/etc/mongodb.conf
Tweak it to your liking.
Start MongoDB instance by running parts start mongodb
Now you can create a new meteor project - meteor create projectname
Finally, when you're starting meteor on your project specify the MONGO_URL environment variable. eg: MONGO_URL=mongodb://0.0.0.0:27017 meteor.
Hope this would be good enough to get started. You can also upgrade your Nitrous.IO account to increase the storage of your box.
UPDATE: I just noticed that Meteor runs its MongoDB instance with --smallfiles flag set.

where is the mongodb database when the meteor instance is not running

In Meteor, each new application I create, it creates a new MongoDb instance and when I run the instance by typing "meteor" it is available until I stop Meteor.
I can save data etc. into this mongodb and the next time I boot up meteor, it should appear again.
So I'm just wondering, where are these mongodbs being stored? how can I access one when I don't have the meteor server running?
The actual data files are stored under the project directory under the path .meteor/local/db, so it really is just a matter of starting up an independent instance when your meteor server is not running:
$:~/myapp$ mongod --smallfiles --dbpath .meteor/local/db --port 30000
And of course with port and/or IP binding that does not conflict with another instance, and of course without the meteor process having started a mongod instance on this data already.
But you are probably better off just defining an external server to your project and just running that separately. Just define the environment variable so the startup process knows which mongodb instance to use:
export MONGO_URL=mongodb://your_host:27017/your_db
Or otherwise essentially replacing your_host and possibly the port as well as your_db with the target details of the server and database you want to use.

How is MongoDb installed by Meteor?

I'm new to both Meteor.js and MongoDB and after installing Meteor in the official way described I wonder how to connect to my MongoDB.
MongoDB was installed by Meteor during the installation and everything works fine but now I would like to have a look into it with another tool (like RazorSQL) to see what's in there.
But the standard connection parameters (localhost:27017) doesn't work, what can I do? Login? Password?
Update: February 2014 - Meteor 0.7.1 - The meteor port has been shifted to 3001 instead of 3002. So instead of adding two to the port meteor runs on, you add 1 instead.
MongoDB's database is installed in the meteor package containing your files in a hidden folder called .meteor. To access it from a remote tool simply add 2 to whatever your web server port is while meteor is running. It will be stored in the meteor database
e.g
http://localhost:3000 would have its mongodb server running at mongodb://localhost:3002/meteor there is no username/password on this instance if you ran it with meteor or meteor run
To get the Meteor Mongo url and port, first run your Meteor app using meteor run then run meteor mongo in a different terminal tab. You should see an output like this
[meteor-app] meteor mongo
MongoDB shell version: 2.6.7
connecting to: 127.0.0.1:3001/meteor
this means that your Meteor Mongo is running at 127.0.0.1:3001.
If you are running your Meteor app with meteor run then you neither need username/password nor authentication configuration just make sure that you set your default database name as meteor

ideal vm setup for meteor with shared folder

situation
Hello, I run arch Linux for which there is no meteor package and have an Ubuntu server run within virtualbox for web development. There is a shared folder I mount through database. hich means I can code in to the active environment.
However, like many others, I have a problem with mongodb starting up, specifically the exit code 100.
tracing the problem:
I created the /data/DB directory
gave access rights to my user
ran mongod on its own with no problems
Still I have the issue though.
Question
Where is the configuration file for mongodb which is installed with meteor so I can move it and do I need to create rights for a 'mongodb' user?
Question
What would be the ideal virtual machine for running a meteor development environment in the above set up? Having to create the data directory in the first place tells me Ubuntu server isn't ideal. some extra documentation available to answer this second question appearing on the meteor website would be beautiful
MongoDB does not work correctly on virtualbox shared folders. By default, meteor creates a mongo database in your project's directory, however you can override this behavior with the MONGO_URL environment variable. If you set this variable, meteor will not try to start mongo and will instead connect directly to the mongo endpoint you specify. This allows you to setup mongo however you like (eg using the Ubuntu mongodb package), with data somewhere not in the shared folder.

Categories