【问题标题】:Updating a collection based on the value extracted from another collection根据从另一个集合中提取的值更新集合
【发布时间】:2021-03-22 02:39:51
【问题描述】:

我正在修改我之前的问题。我有一个名为 FileCollection 的集合,其中包含以下文档:

{
"_id": {
    "$oid": "5e791a53185fbb070378660a"
},
"selectedfiles": [{
"inputfile": "https://localhost/_HAC-154_1584994899979.jpg",
"Selectedby: "Joe"
}]}

我需要将 selectedfiles.inputfile 的值作为字符串变量读取。我正在尝试使用以下代码在 Python 中执行此操作:

from pymongo import MongoClient
mydb = MongoClient(mongodbConnection)
myCollection=mydb.FileCollection
myValue=myCollection.selectedfile[0].inputfile.value
print(myValue)
client.close

输出是一个 JSON,没有 inputfile 的实际值。请帮忙。

谢谢

【问题讨论】:

  • 您能否向我们展示示例数据、预期输出和您当前的代码?

标签: python mongodb mongodb-query


【解决方案1】:

不只是因为你缺少s吗?

你有:

myValue=myCollection.selectedfile[0].inputfile.value

代替:

myValue=myCollection.selectedfiles[0].inputfile.value

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    • 2019-10-18
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    相关资源
    最近更新 更多