MeteorJS: use mongo shell without building meteor app [duplicate] - mongodb

I would like to find out how to connect to an external MongoDB instance in Meteor.
I have added this environment
Meteor.startup(function () {
process.env.MONGO_URL = 'mongodb://[UN]:PW]#[host]:[port]/meteorTest'
});
but still the data is coming from the local database.
I want to move all the collections from my local db to this external db. I read all the tutorials, its all telling me to setup this evn variable but nothing really working. How do I test whether its connected or not?

In my own experience; I have needed to set the environment variable before starting the meteorjs server app. To do this you will need to pass the environment variable on the command-line as you invoke meteor or preset the environment for the profile that is running the meteor app on your system.
So you would start your app with this kind of a command:
MONGO_URL='mongodb://user:password#remote.domain.com:12345/' meteor
You should also make sure that the mongodb is reachable and that your user credentials are correct! I am assuming you are trying to run meteor on your local machine using a remote mongodb instance.
On Windows
You will have to create a batch file in your meteor application folder to invoke the environment variable. There is an example of this here: https://stackoverflow.com/a/29833177/1997579

I don't like to use big repeating command and I was searching for a solution where I will be setting a variable embedded with something so every time I start my meteor app; the MONGO_URL will set to environment automatically. So this what I did:
In the package.json file I replaced the start parameter as below:
"scripts": {
"start": "MONGO_URL=mongodb://username:password#host_url:portnumber/dbname meteor run"
},
Now every time I want to run my app; I run npm start instead of meteor or meteor run
Note: there is a disadvantage with that. Your db credentials will be exposed if you put your db credentials to package.json file and add this file to version control.

run it in command prompt:
"MONGO_URL=mongodb://<USER>:<PASSWORD>#<SERVER>:<PORT>/<DB> meteor"
or
save this url in run.sh file in project folder and run meteor

On windows, I set MONGO_URL in my system's environment variable and it worked fine for me.
I have created a new environment variable and it's value as MONGO_URL=mongodb://username:password#host_url:portnumber/dbname
And in path variable, I have added %MONGO_URL%
Then in meteor app root folder, I have run $meteor

Related

How to connect to external MongoDB instance in Meteor?

I would like to find out how to connect to an external MongoDB instance in Meteor.
I have added this environment
Meteor.startup(function () {
process.env.MONGO_URL = 'mongodb://[UN]:PW]#[host]:[port]/meteorTest'
});
but still the data is coming from the local database.
I want to move all the collections from my local db to this external db. I read all the tutorials, its all telling me to setup this evn variable but nothing really working. How do I test whether its connected or not?
In my own experience; I have needed to set the environment variable before starting the meteorjs server app. To do this you will need to pass the environment variable on the command-line as you invoke meteor or preset the environment for the profile that is running the meteor app on your system.
So you would start your app with this kind of a command:
MONGO_URL='mongodb://user:password#remote.domain.com:12345/' meteor
You should also make sure that the mongodb is reachable and that your user credentials are correct! I am assuming you are trying to run meteor on your local machine using a remote mongodb instance.
On Windows
You will have to create a batch file in your meteor application folder to invoke the environment variable. There is an example of this here: https://stackoverflow.com/a/29833177/1997579
I don't like to use big repeating command and I was searching for a solution where I will be setting a variable embedded with something so every time I start my meteor app; the MONGO_URL will set to environment automatically. So this what I did:
In the package.json file I replaced the start parameter as below:
"scripts": {
"start": "MONGO_URL=mongodb://username:password#host_url:portnumber/dbname meteor run"
},
Now every time I want to run my app; I run npm start instead of meteor or meteor run
Note: there is a disadvantage with that. Your db credentials will be exposed if you put your db credentials to package.json file and add this file to version control.
run it in command prompt:
"MONGO_URL=mongodb://<USER>:<PASSWORD>#<SERVER>:<PORT>/<DB> meteor"
or
save this url in run.sh file in project folder and run meteor
On windows, I set MONGO_URL in my system's environment variable and it worked fine for me.
I have created a new environment variable and it's value as MONGO_URL=mongodb://username:password#host_url:portnumber/dbname
And in path variable, I have added %MONGO_URL%
Then in meteor app root folder, I have run $meteor

How to run a mongo script from Heroku scheduler?

I have implemented a javascript script for my mongo database. This script is called getMetrics.js and I am able to execute it by running: mongo getMetrics.js from my computer.
Now I want to automatically execute that script one time per day. To do so, I have created a Heroku app and I added to it the scheduler add-on (https://devcenter.heroku.com/articles/scheduler).
My main problem is that in order to be run, my task will execute the command "mongo getMetrics.js" and it will failed because I don't have mongo command installed in my Heroku app.
How can I run this script from Heroku?
Thanks a lot for your help.
I did the below in a similar case:
Download mongodb for linux https://www.mongodb.com/download-center#community
The bin folder contains the mongo binary
Make this binary available in your Heroku instance (e.g. If you have your Heroku configured with your git repo, then checkin this binary along side your script
[Make sure the folder you are keeping this binary is in the path, safe path will be inside /bin]

how do i know which mongodb instance meteor.js connects to?

I think I have multiple instances of mongo available on my laptop. How do I know which instance meteor connects to. Also, is there a way to get into the shell of that instance?
By default meteor will automatically use its built in Mongo client. If you are connecting to this you can access its shell by calling meteor mongo whenever your meteor application is runningĀ·
To test which database is being accessed you can access the MONGO_URL environment variable which is set when you launch your application. Adding a console.log(process.env.NODE_ENV); somewhere within your server side codebase should trigger it to be printed to the terminal.

How to persist mongodb when deploying with meteor?

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.

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.