Add Key-Value-Pairs
This page explains how to add a key-value pair to a Key-Value Store collection.
- Web Console
 - Python SDK
 - JavaScript SDK
 
Follow these instructions to add key-value pairs to an existing key-value store collection using the GDN console web UI.
Click Data > Collections.
In the collection list, click the name of the key-value collection to which you want to add a key-value pair. If you aren't sure which collections are key-value collections, then you can click Key-Value at the top of the page to see just key-value collections.
Click New Pair.
(Optional) Enter information in fields.
- _key - Optional. If left blank, then Macrometa automatically generates a key.
 - Value - Enter an individual value.
 - Expire At - Required if expiration was enabled when the collection was created, not visible otherwise.
 - Group ID - Enter a group ID. Only available if Group was selected when the collection was created.
 
Click Create.
Macrometa creates the new key-value record.
The code example below shows how to insert key-value pairs into the collection.
  from c8 import C8Client
  key = "<your-api-key>"
  collection_name = "students"
  # Create a connection to GDN
  client = C8Client(protocol='https', host='play.paas.macrometa.io', port=443,
  apikey=key)
  # Insert key-value pairs
  data = [
    {
      "_key": "John",
      "value": "Science",
      "expireAt": 0
    },
    {
      "_key": "Alice",
      "value": "Maths",
      "expireAt": 0
    },
    {
      "_key": "Alex",
      "value": "Physics",
      "expireAt": 0
    },
    {
      "_key": "Monika",
      "value": "Chemistry",
      "expireAt": 0
    }
  ]
  client.insert_key_value_pair(collection_name, data)
  print("Key-value pairs inserted")
The code example below shows how to insert key-value pairs into the collection.
  // Insert key-value pairs
  var data = [
    {
      "_key": "John",
      "value": "Science",
      "expireAt": 0
    },
    {
      "_key": "Alice",
      "value": "Maths",
      "expireAt": 0
    },
    {
      "_key": "Alex",
      "value": "Physics",
      "expireAt": 0
    },
    {
      "_key": "Monika",
      "value": "Chemistry",
      "expireAt": 0
    }
  ]
  try{
      await client.insertKVPairs(collectionName, data);
      console.log("Key-value pairs inserted successfully.");
  }
  catch(e){
      console.log("Key-value Pairs not inserted due to " + e);
  }