test_cursor.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码
def test_count_with_hint(self, test_db, mongo_version):
        collection = test_db.test

        await collection.insert_many([{'i': 1}, {'i': 2}])
        assert 2 == await collection.find().count()

        await collection.create_index([('i', 1)])

        assert 1 == await collection.find({'i': 1}).hint('_id_').count()
        assert 2 == await collection.find().hint('_id_').count()

        with pytest.raises(OperationFailure):
            await collection.find({'i': 1}).hint('BAD HINT').count()

        # Create a sparse index which should have no entries.
        await collection.create_index([('x', 1)], sparse=True)

        assert 0 == await collection.find({'i': 1}).hint('x_1').count()
        assert 0 == await collection.find({'i': 1}).hint([('x', 1)]).count()

        if mongo_version.at_least(3, 3, 2):
            assert 0 == await collection.find().hint('x_1').count()
            assert 0 == await collection.find().hint([('x', 1)]).count()
        else:
            assert 2 == await collection.find().hint('x_1').count()
            assert 2 == await collection.find().hint([('x', 1)]).count()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号