python - 使用 python 读取具有复杂列表层次结构的 mongodb 集合
问题描述
我有一个 python 脚本,它应该从一个数据库中获取密钥,然后将它们插入另一个 MongoDB。现在集合类似于 Collection contract[]下面的结构
工程师姓名:“约翰”,工作:“医院建设”,截面(0)[{unit1:wardA,长度:40 英尺宽度:10 英尺,高度:10 英尺,照明环境:60%},窗户[3]],截面(1) [{unit1:wardB,Length:40ftx, Width: 60 ft Height 8ft, Lightingambiance: 40%}, Windows[5]],section(2)[{unit1:wardC,Length: Width: Height, Lightingambiance: 50%} , Windows[10]] 其中 window 是另一个包含层次结构的列表。
localCol = localDb["Contracts"] <---mongodb
documents = list(localCol.find())
for doc in documents:
sectionsArray = doc["sectional"]
#print("Length sections array",len(sectionalArray))
for i in sectionalArray:
#find window attribute in sectionalArray
if "products" in sectionalArray:
print("sections.0.products.0.firmProductId",doc["sectionals.0.windows"])
#print("Yes, 'at' found in List sections.5.products : ", sectionalsArray)
无论我做什么,我都无法引用 Windows 项目列表,但文档和部分都可以。
解决方案
推荐阅读
- python - 类型错误:search() 缺少 1 个必需的位置参数:“名称”
- html - 下拉列表验证角度
- c# - 无法在两个 datetimepicker 之间过滤 datagridview
- algorithm - 有限制地将 n 个数加到 k 的方法数
- java - Spring Retry Template 阻止了我的响应队列
- python - 接受 Unix 时间戳作为整数并转换为 DateTimeField 以保存在 django
- javascript - 调用类构造函数来模拟 javascript 中的多态性
- nativescript - 如何在 nativescript 中进行圆形旋转(如掷硬币)过渡?
- arrays - 在下一个单元格中使用电子表格 ID 或 URL 导入范围
- vba - VBA - 当变量值时在单元格中显示公式