Create a Key-Value Store
This page explains how to create a new Key-Value Store collection.
Create a Key-Value Store Collection with the Console
Follow these instructions to create a new collection using the GDN console web UI.
Click Collections.
Click New Collection.
Click Key-Value Store.
Enter information about the collection and then click Create.
- Name - Required. A unique name to distinguish the collection. Spaces are not allowed.
- Expiration - Enable expiration. This allows key-value documents to be removed at a certain date and time.
- Enable Collection stream - Create a stream for this collection. You can do this now or after the collection is created.
- Wait for sync - Synchronize to disk before completing record creation or update.
Create Key-Value Store Collection with Code
This code example shows how to create a collection for saving the key-value pairs.
- Python
- Javascript
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)
# Create a new collection if it does not exist
if client.has_collection(collection_name):
print("Collection exists")
else:
client.create_collection_kv(name=collection_name)
// Add this snippet in previously created main function
let coll = await client.getKVCollections();
console.log("Existing Collections: ", coll.result);
try{
await client.createKVCollection(collectionName);
console.log("Collection Created Successfully");
}
catch(e){
console.log("Collection creation did not succeed due to " + e);
}