本文整理汇总了Python中pymongo.connection.Connection.drop_collection方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.drop_collection方法的具体用法?Python Connection.drop_collection怎么用?Python Connection.drop_collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.connection.Connection
的用法示例。
在下文中一共展示了Connection.drop_collection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DatastoreMongoStub
# 需要导入模块: from pymongo.connection import Connection [as 别名]
# 或者: from pymongo.connection.Connection import drop_collection [as 别名]
class DatastoreMongoStub(apiproxy_stub.APIProxyStub):
"""Persistent stub for the Python datastore API, using MongoDB to persist.
A DatastoreMongoStub instance handles a single app's data.
"""
def __init__(self,
app_id,
datastore_file=None,
require_indexes=False,
service_name='datastore_v3'):
"""Constructor.
Initializes the datastore stub.
Args:
app_id: string
datastore_file: ignored
require_indexes: bool, default False. If True, composite indexes must
exist in index.yaml for queries that need them.
service_name: Service name expected for all calls.
"""
super(DatastoreMongoStub, self).__init__(service_name)
assert isinstance(app_id, basestring) and app_id != ''
self.__app_id = app_id
self.__require_indexes = require_indexes
self.__trusted = True
# TODO should be a way to configure the connection
self.__db = Connection()[app_id]
# NOTE our query history gets reset each time the server restarts...
# should this be fixed?
self.__query_history = {}
self.__next_index_id = 1
self.__indexes = {}
self.__index_lock = threading.Lock()
self.__cursor_lock = threading.Lock()
self.__next_cursor = 1
self.__queries = {}
self.__id_lock = threading.Lock()
self.__id_map = {}
# Transaction support
self.__next_tx_handle = 1
self.__tx_writes = {}
self.__tx_deletes = set()
self.__tx_actions = []
self.__tx_lock = threading.Lock()
def Clear(self):
"""Clears the datastore.
This is mainly for testing purposes and the admin console.
"""
for name in self.__db.collection_names():
if not name.startswith('system.'):
self.__db.drop_collection(name)
self.__queries = {}
self.__query_history = {}
self.__indexes = {}
self.__id_map = {}
self.__next_tx_handle = 1
self.__tx_writes = {}
self.__tx_deletes = set()
self.__tx_actions = []
self.__db.datastore.drop()
def MakeSyncCall(self, service, call, request, response):
""" The main RPC entry point. service must be 'datastore_v3'.
So far, the supported calls are 'Get', 'Put', 'Delete', 'RunQuery', 'Next',
and 'AllocateIds'.
"""
self.AssertPbIsInitialized(request)
super(DatastoreMongoStub, self).MakeSyncCall(
service, call, request, response)
self.AssertPbIsInitialized(response)
def AssertPbIsInitialized(self, pb):
"""Raises an exception if the given PB is not initialized and valid."""
explanation = []
assert pb.IsInitialized(explanation), explanation
pb.Encode()
def QueryHistory(self):
"""Returns a dict that maps Query PBs to times they've been run."""
return dict((pb, times) for pb, times in self.__query_history.items()
if pb.app() == self.__app_id)
def __collection_for_key(self, key):
collection = key.path().element(-1).type()
#.........这里部分代码省略.........