def test_hint(self, test_db):
with pytest.raises(TypeError):
test_db.test.find().hint(3.5)
await test_db.test.drop()
await test_db.test.insert_many([{'num': i, 'foo': i} for i in range(100)])
with pytest.raises(OperationFailure):
await test_db.test.find({'num': 17, 'foo': 17}).hint([('num', ASCENDING)]).explain()
with pytest.raises(OperationFailure):
await test_db.test.find({'num': 17, 'foo': 17}).hint([('foo', ASCENDING)]).explain()
spec = [('num', DESCENDING)]
await test_db.test.create_index(spec)
first = await self._next(test_db.test.find())
assert 0 == first.get('num')
first = await self._next(test_db.test.find().hint(spec))
assert 99 == first.get('num')
with pytest.raises(OperationFailure):
await test_db.test.find({'num': 17, 'foo': 17}).hint([('foo', ASCENDING)]).explain()
a = test_db.test.find({'num': 17})
a.hint(spec)
async for _ in a:
break
with pytest.raises(InvalidOperation):
a.hint(spec)
评论列表
文章目录