本文整理汇总了Python中pymongo.database.Database.set_profiling_level方法的典型用法代码示例。如果您正苦于以下问题:Python Database.set_profiling_level方法的具体用法?Python Database.set_profiling_level怎么用?Python Database.set_profiling_level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.database.Database
的用法示例。
在下文中一共展示了Database.set_profiling_level方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCursor
# 需要导入模块: from pymongo.database import Database [as 别名]
# 或者: from pymongo.database.Database import set_profiling_level [as 别名]
#.........这里部分代码省略.........
self.assertEqual(50, len(list(self.db.test.find(max_scan=50))))
self.assertEqual(50, len(list(self.db.test.find()
.max_scan(90).max_scan(50))))
def test_with_statement(self):
if sys.version_info < (2, 6):
raise SkipTest("With statement requires Python >= 2.6")
self.db.drop_collection("test")
for _ in range(100):
self.db.test.insert({})
c1 = self.db.test.find()
exec """
with self.db.test.find() as c2:
self.assertTrue(c2.alive)
self.assertFalse(c2.alive)
with self.db.test.find() as c2:
self.assertEqual(100, len(list(c2)))
self.assertFalse(c2.alive)
"""
self.assertTrue(c1.alive)
def test_comment(self):
if is_mongos(self.client):
raise SkipTest("profile is not supported by mongos")
if not version.at_least(self.db.connection, (2, 0)):
raise SkipTest("Requires server >= 2.0")
if server_started_with_auth(self.db.connection):
raise SkipTest("SERVER-4754 - This test uses profiling.")
def run_with_profiling(func):
self.db.set_profiling_level(OFF)
self.db.system.profile.drop()
self.db.set_profiling_level(ALL)
func()
self.db.set_profiling_level(OFF)
def find():
list(self.db.test.find().comment('foo'))
op = self.db.system.profile.find({'ns': 'pymongo_test.test',
'op': 'query',
'query.$comment': 'foo'})
self.assertEqual(op.count(), 1)
run_with_profiling(find)
def count():
self.db.test.find().comment('foo').count()
op = self.db.system.profile.find({'ns': 'pymongo_test.$cmd',
'op': 'command',
'command.count': 'test',
'command.$comment': 'foo'})
self.assertEqual(op.count(), 1)
run_with_profiling(count)
def distinct():
self.db.test.find().comment('foo').distinct('type')
op = self.db.system.profile.find({'ns': 'pymongo_test.$cmd',
'op': 'command',
'command.distinct': 'test',
'command.$comment': 'foo'})
self.assertEqual(op.count(), 1)