i want to insert a json file in RavenDb with python

151 Views Asked by At

I am looking for a method, on how can I insert values as JSON format in RavenDB with python.

code:

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()
1

There are 1 best solutions below

0
On

Assuming you want to read a JSON file and put that in RavenDB, you can use:

    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()