1

I'm trying to insert some data into a GridDB container using the Python API, but it doesn't seem to be working. Here's my code:

import griddb_python as griddb

factory = griddb.StoreFactory.get_instance()
store = factory.get_store(
    host='localhost',
    port=2406,
    cluster_name='mycluster',
    username='admin',
    password='admin'
)

conInfo = griddb.ContainerInfo("mycontainer",
                               [["id", griddb.Type.INTEGER],
                                ["name", griddb.Type.STRING]],
                               griddb.ContainerType.COLLECTION, True)

con = store.get_container(conInfo)
con.put([1, "John"])
con.put([2, "Jane"])

When I run this code, it doesn't raise any errors, but when I try to query the container, it's empty. What am I doing wrong?

I tried to look on the internet for a solution, but it seems nothing is working.

John Woods
  • 71
  • 2

1 Answers1

0

One thing that could be causing the issue is that you haven't called con.create() after creating the container. The create() method initializes the container, which is necessary before you can insert data into it.

Here's an updated version of your code that should work:

import griddb_python as griddb

factory = griddb.StoreFactory.get_instance()
store = factory.get_store(
    host='localhost',
    port=2406,
    cluster_name='mycluster',
    username='admin',
    password='admin'
)

conInfo = griddb.ContainerInfo("mycontainer",
                               [["id", griddb.Type.INTEGER],
                                ["name", griddb.Type.STRING]],
                               griddb.ContainerType.COLLECTION, True)

con = store.get_container(conInfo)
con.create() # Initialize the container
con.put([1, "John"])
con.put([2, "Jane"])
Hass786123
  • 666
  • 2
  • 7
  • 16