当前位置: 首页>>代码示例>>Python>>正文


Python MongoClient.write_concern方法代码示例

本文整理汇总了Python中pymongo.mongo_client.MongoClient.write_concern方法的典型用法代码示例。如果您正苦于以下问题:Python MongoClient.write_concern方法的具体用法?Python MongoClient.write_concern怎么用?Python MongoClient.write_concern使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymongo.mongo_client.MongoClient的用法示例。


在下文中一共展示了MongoClient.write_concern方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_write_concern

# 需要导入模块: from pymongo.mongo_client import MongoClient [as 别名]
# 或者: from pymongo.mongo_client.MongoClient import write_concern [as 别名]
    def test_write_concern(self):
        c = MongoClient(pair)

        self.assertEqual({}, c.write_concern)
        wc = {"w": 2, "wtimeout": 1000}
        c.write_concern = wc
        self.assertEqual(wc, c.write_concern)
        wc = {"w": 3, "wtimeout": 1000}
        c.write_concern["w"] = 3
        self.assertEqual(wc, c.write_concern)
        wc = {"w": 3}
        del c.write_concern["wtimeout"]
        self.assertEqual(wc, c.write_concern)

        wc = {"w": 3, "wtimeout": 1000}
        c = MongoClient(pair, w=3, wtimeout=1000)
        self.assertEqual(wc, c.write_concern)
        wc = {"w": 2, "wtimeout": 1000}
        c.write_concern = wc
        self.assertEqual(wc, c.write_concern)

        db = c.pymongo_test
        self.assertEqual(wc, db.write_concern)
        coll = db.test
        self.assertEqual(wc, coll.write_concern)
        coll.write_concern = {"j": True}
        self.assertEqual({"j": True}, coll.write_concern)
        self.assertEqual(wc, db.write_concern)

        wc = SON([("w", 2)])
        coll.write_concern = wc
        self.assertEqual(wc.to_dict(), coll.write_concern)

        def f():
            c.write_concern = {"foo": "bar"}

        self.assertRaises(ConfigurationError, f)

        def f():
            c.write_concern["foo"] = "bar"

        self.assertRaises(ConfigurationError, f)

        def f():
            c.write_concern = [("foo", "bar")]

        self.assertRaises(ConfigurationError, f)
开发者ID:rozza,项目名称:mongo-python-driver,代码行数:49,代码来源:test_common.py


注:本文中的pymongo.mongo_client.MongoClient.write_concern方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。