Create a Document Collection
This page explains how to create a new Document collection.
- Web Console
- Python SDK
- Javascript SDK
- REST API
- CLI
Follow these instructions to create a new collection using the GDN console web UI.
Click Data > Collections.
Click New Collection.
Click Document.
Enter information about the collection:
- Collection Name - Required. A unique name to distinguish the collection. Spaces are not allowed.
- Collection stream - Enable streams for all locations for this collection.
- Strong consistency - Enable strong consistency on this collection. For more information, refer to Strong consistency.
- Distribution - Required. Select whether to store data globally or locally. Default is Global.
Click Create. If you are missing required information, then you cannot complete this step.
The below example shows the steps for connecting a fabric and then creating a collection called employees
.
# Simple approach
client = C8Client(protocol='https', host='play.paas.macrometa.io', port=443,
email='nemo@nautilus.com', password='xxxxx',
geofabric='_system')
client.create_collection(name='employees')
const jsc8 = require("jsc8");
// Email and password to authenticate client instance
const email = "nemo@nautilus.com";
const password = "xxxxxx";
const fabric = "_system";
const collectionName = "employees";
const client = new jsc8({
url: "https://play.paas.macrometa.io",
fabricName: fabric
});
// Or use one of the following authentication methods and remove the commenting.
// Create an authenticated instance with a JWT token.
// const clientUsingJwt = new jsc8({url: "https://play.paas.macrometa.io" , token: "XXXX" , fabricName: fabric});
// Create an authenticated instance with an API key.
// const clientUsingApiKey = new jsc8({url: "https://play.paas.macrometa.io" , apiKey: "XXXX" , fabricName: fabric });
function messageHandler (error) {
const message = {
"StatusCode ": error.statusCode,
"ErrorMessage ": error.message,
"ErrorNum ": error.errorNum
};
console.log(message);
}
async function createCollection () {
await client
.login(email, password)
.then((e) => console.log("1. User authentication done!"))
.catch((error) => error);
console.log("2. Creating collection employees in " + fabric + " fabric");
await client
.createCollection(collectionName, {
stream: true,
waitForSync: false,
isLocal: false
})
.then((collectionDetails) => {
console.log(
"Collection " + collectionDetails.name + " created successfully"
);
console.log(collectionDetails);
})
.catch((error) => messageHandler(error));
}
createCollection()
.then()
.catch((error) => console.log(error));
Use our interactive API Reference with code generation in 18 programming languages to create a Document Collection.
Use the gdnsl collection CLI command to create a Document collection.