Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91

445 views
Skip to first unread message

Russell Bateman

unread,
Jan 22, 2013, 5:29:10 PM1/22/13
to mongodb-user
I'm getting this error when, in fact, I don't think I'm even trying to do anything with 27017 because that's not the port I'm running MongoDB on.

Set-up: 5 replica nodes, ports 37017..37021.

I am trying to run the MongoDB shell and do stuff in the database on the VM running the node whose port number is 37017. I see this:

uas-replicas:PRIMARY> db.connect( "partnerdb" )
Tue Jan 22 14:19:43 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91


Database partnerdb doesn't exist yet. I'm trying to create it new and stuff a new document inside a new collection inside it. It could be a peculiarity of replica sets, though I think I've done this before and it's worked. I can do all kinds of other things from the shell inside this running instance of MongoDB with no problem at all.

What am I missing?

Thanks for any help!

Russ

Russell Bateman

unread,
Jan 22, 2013, 7:20:15 PM1/22/13
to mongodb-user
It appears that

    db.connect( dbname )

isn't a happy experience in the shell. I used

    use partnerdb

instead and that worked. What I'm looking for is how to write a JavaScript that I can use to update an existing database. I'm sure I've used db.connect() like this before, though. I'm not a super-duper JavaScript guy, however. In fact, before MongoDB, I did almost nothing in it.

Still hopeful for suggestions even though I've found a manual work-around.

Jeff Lee

unread,
Jan 22, 2013, 7:28:29 PM1/22/13
to mongod...@googlegroups.com
Russell,

I think you want getSiblingDB?

e.g.

> db.version()
2.2.2
> show dbs
local (empty)
> db.getSiblingDB('mynewdb').foodle.save({id:1})
> show dbs
local (empty)
mynewdb 0.03125GB
> db.getSiblingDB('mynewdb').foodle.find()
{ "_id" : ObjectId("50ff2e1fb1b8d41aac46783d"), "id" : 1 }




--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Russell Bateman

unread,
Jan 22, 2013, 7:36:39 PM1/22/13
to mongod...@googlegroups.com
Oops, sorry. I keep making this knee-jerk mistake (beats about head violently with fists). No wonder no one answered the first time. The command I'm not successful with (that's giving me the error) is:

    db = connect( dbname )

...where dbname is a new database. The idea being that afterward, I'll be doing inserts like:

    db.collectionname.insert( { ... } )

I've fixed this in my examples below. Thanks for replying to my wrongly worded question, though.

Russ



On 1/22/2013 5:28 PM, Jeff Lee wrote:
Russell,

I think you want getSiblingDB?

e.g.

> db.version()
2.2.2
> show dbs
local (empty)
> db.getSiblingDB('mynewdb').foodle.save({id:1})
> show dbs
local (empty)
mynewdb 0.03125GB
> db.getSiblingDB('mynewdb').foodle.find()
{ "_id" : ObjectId("50ff2e1fb1b8d41aac46783d"), "id" : 1 }


On Tue, Jan 22, 2013 at 4:20 PM, Russell Bateman <ru...@windofkeltia.com> wrote:
It appears that

    db = connect( dbname )


isn't a happy experience in the shell. I used

    use partnerdb

instead and that worked. What I'm looking for is how to write a JavaScript that I can use to update an existing database. I'm sure I've used db = connect() like this before, though. I'm not a super-duper JavaScript guy, however. In fact, before MongoDB, I did almost nothing in it.


Still hopeful for suggestions even though I've found a manual work-around.



On 1/22/2013 3:29 PM, Russell Bateman wrote:
I'm getting this error when, in fact, I don't think I'm even trying to do anything with 27017 because that's not the port I'm running MongoDB on.

Set-up: 5 replica nodes, ports 37017..37021.

I am trying to run the MongoDB shell and do stuff in the database on the VM running the node whose port number is 37017. I see this:

uas-replicas:PRIMARY> db = connect( "partnerdb" )

Tue Jan 22 14:19:43 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91

gregor

unread,
Jan 23, 2013, 6:14:27 AM1/23/13
to mongod...@googlegroups.com
Connect connects to a new host 
not a database. 
Use

use <dbname>
db.<collectionname>.insert({ ... })
Reply all
Reply to author
Forward
0 new messages