Wie speichere und abgerufen Sie komplexe JSON -Dokumente in GridDB mit dem Python -Client?Python

Python-Programme
Anonymous
 Wie speichere und abgerufen Sie komplexe JSON -Dokumente in GridDB mit dem Python -Client?

Post by Anonymous »

Ich versuche, komplexe JSON-ähnliche Dokumente (z. B. verschachtelte Wörterbücher) in GridDB unter Verwendung des Python-Clients zu speichern. GridDB unterstützt Key-Container-Row-Modelle, aber ich bin mir nicht sicher, wie ich verschriebene Objekte umgehen soll.

Code: Select all

from griddb_python import StoreFactory

factory = StoreFactory.get_instance()
gridstore = factory.get_store(host="192.168.0.22", port=10001, cluster_name="Zaigham", username="Zaigham_A", password="admin786")

container_info = griddb.ContainerInfo(
name="sensor_data",
column_info_list=[
("id", griddb.Type.INTEGER),
("payload", griddb.Type.STRING)  # storing as JSON string
],
type=griddb.ContainerType.COLLECTION,
row_key=True
)

gridstore.drop_container("sensor_data")
container = gridstore.put_container(container_info)

import json
data = {
"id": 1,
"payload": json.dumps({"temperature": 24.5, "location": {"lat": 12.34, "lon": 56.78}})
}
container.put(list(data.values()))
Gibt es eine bessere Möglichkeit, verschachtelte JSON -Daten in GridDB zu verarbeiten, anstatt sich zu flach oder als String zu speichern?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post