Create Collection
Collection Creation Parameters
The createCollection method supports the following format:
createCollection( name: string, isEncrypted?: boolean, encryptionKey?: string );
Below are examples of creating collections with different configurations.
Basic Collection (No Encryption)
javascript
1
2const { AxioDB } = require("axiodb");3
4const db = new AxioDB();5const myDB = await db.createDB("MyDatabase");6
7// Create a basic collection (no encryption)8const collection = await myDB.createCollection("users");9console.log("Basic collection created:", collection);Encrypted Collection (Auto-Generated Key)
javascript
1
2// Create an encrypted collection with auto-generated key3const encryptedCollection = await myDB.createCollection("secureUsers", true);4console.log("Encrypted collection created (auto-generated key):", encryptedCollection);Encrypted Collection (Custom Key)
javascript
1
2// Create an encrypted collection with custom encryption key3const customKeyCollection = await myDB.createCollection("vaultUsers", true, "mySecretKey123");4console.log("Encrypted collection created (custom key):", customKeyCollection);Important Notes
- If
falseis passed for schema validation, use{}for the schema. - Encryption keys are generated automatically if not provided.
- Store your custom encryption keys securely—data recovery is impossible without them.
