python - Connecting and Executing mongodb commands remotely through pymongo -
below python code connects remotely mongodb host , executes mongodb command "db.serverstatus().connections".
expected output below script :
{ "current" : 43, "available" : 51157, "totalcreated" : numberlong(3988) }
but i'm not getting output.....
python code:
import pymongo host = 'mongo_server.com' port = 27018 db_name='test' user='user' passwrd='password' def get_connection(): con=pymongo.connection(host,port) db=con[db_name] try: db.authenticate(user,passwrd) print db.command("serverstatus")["connections"] except: return none return db get_connection()
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostn[:portn]]][/[database][?options]]
mongodb:// required prefix identify string in standard connection format.
username:password@ optional. if given, driver attempt login database after connecting database server. authentication mechanisms, username specified , password not, in case ":" after username left off host1 required part of uri. identifies server address connect to.
:portx optional , defaults :27017 if not provided.
/database name of database login , relevant if username:password@ syntax used. if not specified "admin" database used default.
?options connection options. note if database absent there still / required between last host , ? introducing options. options name=value pairs , pairs separated "&". backwards compatibility, ";" accepted separator in addition "&", should considered deprecated.
Comments
Post a Comment