当我尝试插入以下文档时:
aws_data = {u'ami_launch_index': 0,
u'image': ec2.Image(id='xxx')
}
我收到以下错误:
bson.errors.InvalidDocument: Cannot encode object: ec2.Image(id='xxx')
MongoDB无法编码ec2.Image(id='ami-xxx')
我该如何解决?
将镜像 ID 直接存储到 MongoDB。我会建议序列化,但这毫无意义。使用映像 ID,您始终可以执行其他 ec2 API 操作。
aws_data = {
'ami_launch_index': 0,
'image': 'xxx'
}
您不能将几乎任何对象插入到集合中。支持的数据类型包括:
- 国际
- 长
- 浮
- 没有
- 字典
- 列表
- 元
- str
- 布尔
- 日期时间
- 乌伊德
- 映射
- 字节
- 对象标识
- 正则表达式
- 法典
- 时间戳
- DBRef
- RawBSONDocument
- 明基
- 麦克键
- 统一码
https://github.com/mongodb/mongo-python-driver/blob/3.6.0/bson/_cbsonmodule.c#L693