本文整理汇总了Python中pymongo.database.Database.list_collection_names方法的典型用法代码示例。如果您正苦于以下问题:Python Database.list_collection_names方法的具体用法?Python Database.list_collection_names怎么用?Python Database.list_collection_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.database.Database
的用法示例。
在下文中一共展示了Database.list_collection_names方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_drop_collection
# 需要导入模块: from pymongo.database import Database [as 别名]
# 或者: from pymongo.database.Database import list_collection_names [as 别名]
def test_drop_collection(self):
db = Database(self.client, "pymongo_test")
self.assertRaises(TypeError, db.drop_collection, 5)
self.assertRaises(TypeError, db.drop_collection, None)
db.test.insert_one({"dummy": u"object"})
self.assertTrue("test" in db.list_collection_names())
db.drop_collection("test")
self.assertFalse("test" in db.list_collection_names())
db.test.insert_one({"dummy": u"object"})
self.assertTrue("test" in db.list_collection_names())
db.drop_collection(u"test")
self.assertFalse("test" in db.list_collection_names())
db.test.insert_one({"dummy": u"object"})
self.assertTrue("test" in db.list_collection_names())
db.drop_collection(db.test)
self.assertFalse("test" in db.list_collection_names())
db.test.insert_one({"dummy": u"object"})
self.assertTrue("test" in db.list_collection_names())
db.test.drop()
self.assertFalse("test" in db.list_collection_names())
db.test.drop()
db.drop_collection(db.test.doesnotexist)
if client_context.version.at_least(3, 3, 9) and client_context.is_rs:
db_wc = Database(self.client, 'pymongo_test',
write_concern=IMPOSSIBLE_WRITE_CONCERN)
with self.assertRaises(WriteConcernError):
db_wc.drop_collection('test')
示例2: test_create_collection
# 需要导入模块: from pymongo.database import Database [as 别名]
# 或者: from pymongo.database.Database import list_collection_names [as 别名]
def test_create_collection(self):
db = Database(self.client, "pymongo_test")
db.test.insert_one({"hello": "world"})
self.assertRaises(CollectionInvalid, db.create_collection, "test")
db.drop_collection("test")
self.assertRaises(TypeError, db.create_collection, 5)
self.assertRaises(TypeError, db.create_collection, None)
self.assertRaises(InvalidName, db.create_collection, "coll..ection")
test = db.create_collection("test")
self.assertTrue(u"test" in db.list_collection_names())
test.insert_one({"hello": u"world"})
self.assertEqual(db.test.find_one()["hello"], "world")
db.drop_collection("test.foo")
db.create_collection("test.foo")
self.assertTrue(u"test.foo" in db.list_collection_names())
self.assertRaises(CollectionInvalid, db.create_collection, "test.foo")