def test_id_can_be_anything(self, test_db):
await test_db.test.delete_many({})
auto_id = {'hello': 'world'}
await test_db.test.insert_one(auto_id)
assert isinstance(auto_id['_id'], ObjectId)
numeric = {'_id': 240, 'hello': 'world'}
await test_db.test.insert_one(numeric)
assert numeric['_id'] == 240
obj = {'_id': numeric, 'hello': 'world'}
await test_db.test.insert_one(obj)
assert obj['_id'] == numeric
async with test_db.test.find() as cursor:
async for x in cursor:
assert x['hello'] == 'world'
assert '_id' in x
评论列表
文章目录