本文整理汇总了Python中pymongo.mongo_client.MongoClient.server_info方法的典型用法代码示例。如果您正苦于以下问题:Python MongoClient.server_info方法的具体用法?Python MongoClient.server_info怎么用?Python MongoClient.server_info使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.mongo_client.MongoClient
的用法示例。
在下文中一共展示了MongoClient.server_info方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeDBConnection
# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import server_info [as 别名]
def makeDBConnection(port, **kwargs):
global _C
if not _C:
logging.info("establishing db connection at port %s ..." % port)
import pymongo
logging.info("using pymongo version %s" % pymongo.version)
from pymongo.mongo_client import MongoClient
_C = MongoClient(port = port, **kwargs)
mongo_info = _C.server_info()
logging.info("mongodb version: %s" % mongo_info["version"])
示例2: test_mongo
# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import server_info [as 别名]
def test_mongo(self):
client = MongoClient()
db = client.test_database
collection = db.test_collection
import datetime
post = {"author": "Mike",
"text": "My first blog post!",
"tags": ["mongodb", "python", "pymongo"],
"date": datetime.datetime.utcnow()}
posts = db.posts
post_id = posts.insert(post)
print(post_id)
print(client.server_info())
示例3: MongoDBAdapter
# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import server_info [as 别名]
class MongoDBAdapter(DatabaseAdapter):
def __init__(self, url, dbname):
self.logger = logging.getLogger(self.__class__.__name__)
self.client = MongoClient()
self.db = getattr(self.client, dbname)
@_run_in_executor
def info(self):
return self.client.server_info()
@_run_in_executor
def put(self, document, doc_id=None, **options):
collection = document.data['doc_type']
collection = getattr(self.db, collection)
if '_id' in document.data and document.data['_id']:
_id = collection.update(document.data)
else:
if '_id' in document.data:
del document.data['_id']
_id = collection.insert(document.data)
document.data['_id'] = _id
return document
@_run_in_executor
def get(self, doc_id, **options):
response = yield from aiohttp.request(
'GET', urljoin(self._dburl, doc_id),
headers={
'Accept': 'application/json'
})
data = yield from response.read()
return json_loads(data)
def delete(self, doc_id, rev=None, **options):
if rev == None:
rev = yield from self.info(doc_id)
rev = rev._rev
url = '%s?rev=%s' % (urljoin(self._dburl, doc_id), quote(rev))
response = yield from aiohttp.request(
'DELETE', url,
headers={
'Accept': 'application/json'
})
data = yield from response.read()
return Bunch(**json_loads(data))
def all(self, **options):
response = yield from aiohttp.request(
'GET', urljoin(self._dburl, '_all_docs'),
headers={
'Accept': 'application/json'
})
data = yield from response.read()
return Bunch(**json_loads(data))
def put_design_doc(self, ddoc_name, ddoc, **options):
posturl = urljoin(self._dburl, "_design/%s/" % ddoc_name)
response = yield from aiohttp.request(
'PUT', posturl, data=json_dumps(ddoc),
headers={
'Accept': 'application/json',
'content-type': 'application/json'
})
data = yield from response.read()
return Bunch(**json_loads(data))
def view(self, ddoc_name, view, **options):
if not options:
options = {}
options.setdefault('reduce', options.setdefault('group', False))
viewurl = urljoin(
self._dburl, "_design/%s/_view/%s" % (ddoc_name, view))
for option in options:
options[option] = json.dumps(options[option])
query = urlencode(options)
viewurl = "%s?%s" % (viewurl, query)
self.logger.debug('GET: %s', viewurl)
response = yield from aiohttp.request(
'GET', viewurl,
headers={
'Accept': 'application/json',
})
data = yield from response.read()
return ResultList(**self.check_errors(json_loads(data)))