mongodb - Testing motor.MotorClient() connection -


i want know how check motor connection successful. if kill mongod process , perform a:

con = motor.motorclient(host,port) 

i "[w 150619 00:38:38 iostream:1126] connect error on fd 11: econnrefused"

makes sense since there's no server running. because isn't exception i'm not sure how check case?

i thought check con.is_mongos seems it's false (also stated in documentation).

how check above error scenario?

generally, answer don't. don't check if connection mongodb working. might find out it's working right now, next operation might fail anyway--your sysadmin might pull cable, server crashes, whatever. since need handle errors later in application no matter, there's no point checking ahead of time whether motor has connected or not.

if insist on pointless check, knowing gains nothing, do:

@gen.coroutine def am_i_momentarily_connected_to_mongodb():     yield motorclient().admin.command('ismaster') 

if ioloop has started , you're in coroutine can do:

yield am_i_momentarily_connected_to_mongodb() 

or if haven't started loop yet:

ioloop.instance().run_sync(am_i_momentarily_connected_to_mongodb) 

but said, it's nature of distributed systems discovering server available now doesn't tell happen next.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -