def test_max(self, test_db):
await test_db.test.create_index([('j', ASCENDING)])
await test_db.test.insert_many([{'j': j, 'k': j} for j in range(10)])
cursor = test_db.test.find().max([('j', 3)])
assert len(await cursor.to_list()) == 3
# Tuple.
cursor = test_db.test.find().max((('j', 3),))
assert len(await cursor.to_list()) == 3
# Compound index.
await test_db.test.create_index([('j', ASCENDING), ('k', ASCENDING)])
cursor = test_db.test.find().max([('j', 3), ('k', 3)])
assert len(await cursor.to_list()) == 3
# Wrong order.
cursor = test_db.test.find().max([('k', 3), ('j', 3)])
with pytest.raises(OperationFailure):
await cursor.to_list()
# No such index.
cursor = test_db.test.find().max([('k', 3)])
with pytest.raises(OperationFailure):
await cursor.to_list()
with pytest.raises(TypeError):
test_db.test.find().max(10)
with pytest.raises(TypeError):
test_db.test.find().max({'j': 10})
评论列表
文章目录