【问题标题】:i want to insert a json file in RavenDb with python我想用 python 在 RavenDb 中插入一个 json 文件
【发布时间】:2022-07-07 00:06:13
【问题描述】:

我正在寻找一种方法,关于如何使用 python 在 RavenDB 中以 JSON 格式插入值。

代码:

cert = {'pfx': '...', 'password': '...'}
    document_store = document_store.DocumentStore(["link DB"], "name DB", certificate=cert)
    doc = {"id":123, "name": "BLA BLA BLA"}
    id = "TiktokPosts"
    document_store.initialize()
    with document_store.open_session() as session:
        session.store(doc, id)
        session.save_changes()

【问题讨论】:

  • 这里的代码应该......正常工作。
  • 您是在问如何从文件中读取 JSON,然后插入到 RavenDB?

标签: python ravendb ravendb-studio ravendb5


【解决方案1】:

假设您要读取 JSON 文件并将其放入 RavenDB,您可以使用:

    import json
     
    f = open('data.json')
    data = json.load(f)
    
    with document_store.open_session() as session:
            session.store(data , "my-doc-id")
            session.save_changes()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-21
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 2023-02-24
    • 1970-01-01
    相关资源
    最近更新 更多