Discussion:
Getting MongoD replica status via pymongo
Kevin Rice
2013-02-11 20:35:27 UTC
Permalink
Hi!

I'm creating an automated startup script for creating a sharded replicated
database.

When I invoke via the command line: mongo --host blah --port blah --eval
'printjson(rs.status())' I see the following:

MongoDB shell version: 2.0.6
connecting to: myservernamegoeshere.com:30000/test
{
"startupStatus" : 3,
"info" : "run rs.initiate(...) if not yet done for the set",
"errmsg" : "can't get local.system.replset config from self or any seed
(EMPTYCONFIG)",
"ok" : 0
}

I can depend on 'startupStatus' being 3 meaning that I can keep going and
start doing stuff like adding config servers, etc.

But, I'd like to get this information via pymongo. I've tried lots of
import pymongo
conn = pymongo.Connection('myservernamegoeshere.com:30000')
conn.db._adminCommand("replSetGetStatus")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line
1401, in __call__
self.__name)
TypeError: 'Collection' object is not callable. If you meant to call the
'_adminCommand' method on a 'Database' object it is failing because no such
method exists.
conn.admin.command("replSetGetStatus")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line
395, in command
msg, allowable_errors)
File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line
144, in _check_command_response
raise OperationFailure(msg % details["errmsg"])
pymongo.errors.OperationFailure: command SON([('replSetGetStatus', 1)])
failed: can't get local.system.replset config from self or any seed
(EMPTYCONFIG)

How do I get status to know that the daemons have started up correctly ?
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/***@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/***@public.gmane.org
See also the IRC channel -- freenode.net#mongodb

---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Bernie Hackett
2013-02-11 20:43:04 UTC
Permalink
It looks like your replica set isn't actually configured yet. See here
for some example code:

https://github.com/mongodb/mongo-python-driver/blob/master/test/high_availability/ha_tools.py#L90-L181
Post by Kevin Rice
Hi!
I'm creating an automated startup script for creating a sharded replicated
database.
When I invoke via the command line: mongo --host blah --port blah --eval
MongoDB shell version: 2.0.6
connecting to: myservernamegoeshere.com:30000/test
{
"startupStatus" : 3,
"info" : "run rs.initiate(...) if not yet done for the set",
"errmsg" : "can't get local.system.replset config from self or any seed
(EMPTYCONFIG)",
"ok" : 0
}
I can depend on 'startupStatus' being 3 meaning that I can keep going and
start doing stuff like adding config servers, etc.
But, I'd like to get this information via pymongo. I've tried lots of
import pymongo
conn = pymongo.Connection('myservernamegoeshere.com:30000')
conn.db._adminCommand("replSetGetStatus")
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line
1401, in __call__
self.__name)
TypeError: 'Collection' object is not callable. If you meant to call the
'_adminCommand' method on a 'Database' object it is failing because no such
method exists.
conn.admin.command("replSetGetStatus")
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line
395, in command
msg, allowable_errors)
File "/usr/local/lib/python2.7/dist-packages/pymongo/helpers.py", line
144, in _check_command_response
raise OperationFailure(msg % details["errmsg"])
pymongo.errors.OperationFailure: command SON([('replSetGetStatus', 1)])
failed: can't get local.system.replset config from self or any seed
(EMPTYCONFIG)
How do I get status to know that the daemons have started up correctly ?
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To unsubscribe from this group, send email to
See also the IRC channel -- freenode.net#mongodb
---
You received this message because you are subscribed to the Google Groups
"mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/groups/opt_out.
--

Loading...