Working with Data
Instance and database#
const { AxioDB } = require("axiodb");
const Instance = new AxioDB({ GUI: true });
const UserDB = await Instance.createDB("MyDB");
const UserCollection = await UserDB.createCollection("Users");Create multiple isolated databases under the same instance:
const userDB = await db.createDB("UsersDB");
const productsDB = await db.createDB("ProductsDB");Insert#
// Single document — no schema required
await UserCollection.insert({
name: "John Doe",
email: "john.doe@example.com",
age: 30
});
// Multiple documents
await UserCollection.insertMany([
{ name: "Jane Doe", email: "jane.doe@example.com", age: 25 },
{ name: "Alice Smith", email: "alice.smith@example.com", age: 28 }
]);Query#
// Comparison operator
const olderUsers = await UserCollection.query({ age: { $gt: 25 } }).exec();
// Regex
const exampleUsers = await UserCollection.query({
email: { $regex: /example.com$/ }
}).exec();
// Chained: filter, paginate, sort, project
const results = await UserCollection.query({
email: { $in: ["john.doe@example.com", "jane.doe@example.com"] }
})
.Limit(10)
.Skip(2)
.Sort({ age: 1 })
.setCount(true)
.setProject({ _id: 1, name: 1, email: 1 })
.exec();
// Fast lookup by documentId (auto-indexed, O(1) with cache)
const fastRes = await UserCollection.query({ documentId: "JOHTAOIJNHUJOBD" }).exec();Aggregation#
const aggData = await UserCollection.aggregate([
{ $match: { age: { $gt: 25 } } },
{ $group: { _id: "$email", avgAge: { $avg: "$age" } } }
]).exec();Update and delete#
await UserCollection.update({ name: "John Doe" }).UpdateOne({ name: "Ankan" });
await UserCollection.update({ name: "John Doe" }).UpdateMany({ name: "Ankan" });
await UserCollection.delete({ name: "John Doe" }).DeleteOne();
await UserCollection.delete({ name: "John Doe" }).DeleteMany();Transactions#
Full ACID compliance with commit, rollback, and Write-Ahead Logging for crash recovery. Transactions are scoped to a single collection.
Custom indexes#
collection.newIndex('email', 'age', 'name');Supports single and multi-field indexes for faster lookups, range queries, sorting, and filtering.