Problem running meteor locally with a mongodb restored from Atlas snapshot - mongodb

I want to run a localhost meteor locally to debug using data from production database.
I downloaded a daily snapshot fro Mongo Atlas, extracted it to desktop, unzipped it to a folder called "snap"
Then I run:
mongod --dbpath snap -port 3001
I can see the mongodb now running at 127.0.0.1:3001.
I go to start my meteor project locally:
meteor --settings settings.json
Hoping that it will somehow magically pick up the running database at port 3001, but it didnt.
It complains:
=> Started proxy.
Unexpected mongo exit code 48. Restarting.
=> Meteor 2.1 is available. Update this project with 'meteor update'.
Unexpected mongo exit code 48. Restarting.
Unexpected mongo exit code 48. Restarting.
Can't start Mongo server.
MongoDB exited because its port was closed, or was already
taken by a previous instance of MongoDB
Check for other processes listening on port 3001
or other Meteor instances running in the same project.
What should I do to ask Meteor to start the project using that recovered database?

Assuming your DB is running, you can run locally with your own DB using the environment variable MONGO_URL
$ MONGO_URL=mongodb://localhost:<port>/<dbname> meteor run --settings settings.json
Note, that you need to set an explicit name for the db and if your Meteor db already contains data, then you need to import it into this db in order to have access to both.
Furthermore, I would personally avoid setting port 3001 to not confuse it with the db that is bundled with Meteor. You should be fine with Mongo's defualt 27017 port.
References:
https://docs.meteor.com/environment-variables.html#MONGO-URL

Related

Why does the mongo shell work without mongod server being explicitly run?

Running MongoDB Shell v-3.2.8
I've noticed that articles and tutorials always mention to run the mongod server before running the mongo shell.
However, when I skip the first step and simply type mongo into my terminal, the mongo shell works without any errors / interruptions.
MacBook:Desktop user$ mongo
MongoDB shell version: 3.2.8
connecting to: test
Why does this work? Does mongo call mongod?
The mongod is being ran as a service or daemon, which means that there is always a mongod process running listening to a port. I use ubuntu, and when I install mongodb through the package manager, it immediately starts up a mongod process and begins listening on the standard port.
Running mongo is simply a small utility that attempts to connect to the localhost at the standard ip. The data reading, writing, and querying is done by the mongod process while mongo is a small program that sends the the commands to mongod.
If mongod wasn't running, you would see an error stating "Unable to connect to mongodb server"
I noticed the same. I think mongoose is doing some smart things there, which I'm not sure how it works. But I have noticed such things before, like mongoose will automatically add an "s" to your database's name when you declare it, which is a very thoughtful act =)).
I encountered the same thing and found that in the background services if MongoDB server is running, the mongo shell will work without any error. If we stop the service, the shell will throw an error.

Can't connect to local (running) mongo using 'meteor mongo'

I'm playing with meteor, Installed it on Ubuntu 14.10 & followed the todos tutorial. The Meteor run log:
$ meteor run
[[[[[ ~/bckd/homedir/learn/meteor/mycoolapp ]]]]]
=> Started proxy.
=> Started MongoDB.
=> Started your app.
=> App running at: http://localhost:3000/
When I try to connect to mongo via another terminal, I get:
$ meteor mongo
mongo: Meteor isn't running a local MongoDB server.
This command only works while Meteor is running your application locally. Start your
application first. (This error will also occur if you asked Meteor to use a different MongoDB
server with $MONGO_URL when you ran your application.)
If you're trying to connect to the database of an app you deployed with `meteor deploy`,
specify your site's name with this command.
Trying to work around this problem I looked at the mongo command, and soon enough I figured I can connect using:
$ mongo localhost:3001
So great, that's working and it seems that I am able to use that for the time being.
But... why is the official way: meteor mongo not working in my setup, and can I do anything to fix it?
Edit 5/6/2015
After creating another account on my ubuntu, logging in and creating a new app, I run it and managed to connect to the mongo instance as intended with the meteor mongo command (without sudo). I thought it could be a result of a difference in my environment variables so I compared the two (dumping both environments with the env command. There were some extra bash variables in my primary account so one by one I've unset them until I reached two identical environments (with the exceptions of home directory values, user names, auto-generated values for gnome session tokens and such). Despite those changes, the problem consists. Another wild guess of mine was that the ~/.meteor folder has gone evil on me. So, I've removed it and reinstalled meteor. That didn't fix it either. Whatever the problem is, it's pretty stubborn.
Try:
sudo meteor mongo
it worked for me on a Vagrant box :)
You need to be the same user as the user who started Meteor.
Also you need to connect from within the application directory.
Can you connect to the database with the native MongoDB client?
Try running sudo meteor mongo - maybe the Meteor/Node process is running as root.
Looks like it's your environment variable problem.
export MONGO_URL=''
meteor mongo
Did you create the meteor app initially :
meteor create
I was having same issue on Ubuntu and found that i missed the create part as I copied the code from windows machine.
In my case(Windows 10),I had set MONGO_URL='remote url'.
In this case when you type 'meteor mongo' meteor will try to connect to the local mongodb server,but we are pointing to remote mogodb.
To point to local mongodb:
1) befor starting the app type 'set MONOGO_URL=' command in terminal.
2) now start the meteor app
3) now open a new terminal and try 'meteor mongo'
This worked for me with the same problem.
I had two terminals open: one running with meteor command, the other terminal I tried meteor mongo and received the very same message as stated in the question.
mongo: Meteor isn't running a local MongoDB server.
This command only works while Meteor is running your application locally. Start
your application first with 'meteor' and then run this command in a new
terminal. This error will also occur if you asked Meteor to use a different
MongoDB server with $MONGO_URL when you ran your application.
If you're trying to connect to the database of an app you deployed with
'meteor deploy', specify your site's name as an argument to this command.
I tried the sudo command, which did not work as well.
Here is what worked for me.
Goto running meteor server terminal and ctrl-c (shut down server).
In meteor server terminal type: meteor mongo.
Note: In my case the command worked and the terminal entered into mongo.
Type exit to exit mongo.
Type meteor to spool back up meteor server.
Goto meteor mongo terminal and type: meteor mongo.
Note: For me, Meteor was running in the other terminal and meteor mongo command did open meteor mongo for me without error.
Perhaps the something in Meteor needs to reboot which does not occur without shutting down meteor server first?
check if there is a running mongo process, and kill it manually:
ps -aux | grep mongo
sudo kill [pid]
..then restart your meteor app.
--> I think this specific situation exists only when starting meteor on a custom port (not tested, but pretty obvious)

Meteor Mongo Error

I have just set up a meteor localhost app, and when trying to execute "meteor mongo" on the linux terminal, it shows this error:
mongo: Meteor isn't running a local MongoDB server.
This command only works while Meteor is running your application locally. Start
your application first. (This error will also occur if you asked Meteor to use
a different MongoDB server with $MONGO_URL when you ran your application.)
If you're trying to connect to the database of an app you deployed with
'meteor deploy', specify your site's name with this command.
What sould I do??
you need to have mongo server running to run meteor mongo and access it.
first open a terminal window and run your meteor app
meteor run
then open another window and access your mongo db
meteor mongo

Meteor Mongo error

I have just set up a meteor localhost app, and when trying to execute "meteor mongo" on the linux terminal, it shows this error:
mongo: Meteor isn't running a local MongoDB server.
This command only works while Meteor is running your application locally. Start
your application first. (This error will also occur if you asked Meteor to use
a different MongoDB server with $MONGO_URL when you ran your application.)
If you're trying to connect to the database of an app you deployed with
'meteor deploy', specify your site's name with this command.
What should I do??
Pretty much what it says:
Run meteor in one terminal.
Run meteor mongo in another terminal while the first one is still running.

Where is the meteor MongoDB database?

When I create a meteor app, where is the database?
I have an app called leaderboard, but when I run mongo shell and do show dbs I see only local (empty) and test but test doesn't doesn't have the same contents as my leaderboard app. Where does meteor create the Mongo database and how can I access it from mongo shell (so I can load some data into it)?
You need to be running the application with the meteor run command in one session, at which point you can run mongo meteor in another session on the same machine, which will include something like
[kfullert#shotgun ]$ meteor mongo
MongoDB shell version: 2.2.1
connecting to: 127.0.0.1:3002/meteor
At that point, you can use the URL in the "connecting to" line with the standard mongo tools (caveat - you need to be running your project with meteor at the same time, as "meteor run" is what spins up the mongo server for your project
[kfullert#shotgun ]$ mongo 127.0.0.1:3002/meteor
MongoDB shell version: 2.2.3
connecting to: 127.0.0.1:3002/meteor
>
For mongoimport, you'll probably want something like:
[kfullert#shotgun ]$ mongoimport -h 127.0.0.1 --port 3002 -d meteor
Additionally, it may be possible to run mongoimport without meteor running, by using the following switch from your project root directory (untested so beware)
mongoimport --dbpath .meteor/local/db -d meteor
For apps running a local db server, APPDIR/.meteor/local/db
You can connect to your app's mongodb with meteor mongo and then us show collections to list the Meteor.Collections you've created.