【问题标题】:How to manipulate a specific field in a document (PyMongo)如何操作文档中的特定字段(PyMongo)
【发布时间】:2015-11-18 00:52:48
【问题描述】:

例如,我的文档中有一个名为“x”的字段,其中包含一个巨大的字符串。我希望能够逐字阅读字符串。

client = pymongo.MongoClient("localhost", 27017)
db = client.clients
collection = db.unlabel_review

for post in collection.find():
    documents.append(post)

所以这会返回整个 JSON 对象列表,并且在文档上调用某个索引将返回该文档。返回该文档的字段的语法是什么,例如返回“id”或字段“x”,其中 x 包含一个字符串?

直觉上,我想说

documents[1] -> returns whole JSON object so

documents[1][1] -> returns the first index of that JSON object, but this doesn't seem to work

感谢您的帮助:)

【问题讨论】:

    标签: python json mongodb pymongo


    【解决方案1】:

    我想通了,

    documents[1]["field name"] 将返回一个特定的字段。

    【讨论】:

      猜你喜欢
      • 2021-08-15
      • 1970-01-01
      • 2020-04-10
      • 2020-11-21
      • 2019-04-10
      • 2015-07-24
      • 2023-01-23
      • 1970-01-01
      • 2021-05-22
      相关资源
      最近更新 更多