Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is mongo not connecting to my table by command line?

Everything connects properly in my app, but when I try to do so by command line I can't seem to connect.

mongod --port 27018 --dbpath ~/code/server/db/seed
Wed Jul 27 15:49:08 MongoDB starting : pid=84222 port=27018 dbpath=/Users/jeremysmith/code/server/db/seed 64-bit 
Wed Jul 27 15:49:08 db version v1.6.5, pdfile version 4.5
Wed Jul 27 15:49:08 git version: 0eb017e9b2828155a67c5612183337b89e12e291
Wed Jul 27 15:49:08 sys info: Darwin erh2.10gen.cc 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_40
Wed Jul 27 15:49:08 [initandlisten] waiting for connections on port 27018
Wed Jul 27 15:49:08 [websvr] web admin interface listening on port 28018


$ mongo 127.0.0.1:27018
MongoDB shell version: 1.6.5
connecting to: 127.0.0.1:27018/test

> use seeds_db
switched to db seeds_db

> show collections
preferences
sites
stat_definitions
system.indexes

> seeds_db.stat_definitions.find();
Thu Jul 28 12:26:34 ReferenceError: seeds_db is not defined (shell):0

> stat_definitions.find();         
Thu Jul 28 12:26:37 ReferenceError: stat_definitions is not defined (shell):0

> seeds_db['stat_definitions'].find();
Thu Jul 28 12:26:59 ReferenceError: seeds_db is not defined (shell):0
like image 292
Jeremy Smith Avatar asked Jul 28 '11 16:07

Jeremy Smith


People also ask

Why is my MongoDB not connecting?

Ensure that your MongoDB instance is running: Compass must connect to a running MongoDB instance. Also check you have installed MongoDB and have a running mongod process. You should also check that the port where MongoDB is running matches the port you provide in the compass connect.

How do I access MongoDB from command prompt?

To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.

How do you establish connection to MongoDB?

To connect to your local MongoDB, you set Hostname to localhost and Port to 27017 . These values are the default for all local MongoDB connections (unless you changed them). Press connect, and you should see the databases in your local MongoDB.


1 Answers

Do you just need to replace seeds_db with db? eg.

db.stat_definitions.find();
like image 139
Steve Avatar answered Sep 30 '22 11:09

Steve