Getting Started with NexusDB v2.0
NexusDB is a high-performance, distributed NoSQL database built for modern applications. This documentation will guide you through setup, core concepts, and best practices.
Installation
Install NexusDB using npm or download the binary directly:
npm install nexusdb --save
# or using yarn
yarn add nexusdb
# or download binary
curl -sSL https://get.nexusdb.io | sh
💡 System Requirements
NexusDB requires Node.js 18+ or Go 1.20+ depending on your implementation choice.
Quick Start
Connect to NexusDB and perform your first operation:
import { NexusDB } from 'nexusdb';
// Initialize connection
const db = new NexusDB({
host: 'localhost',
port: 7687,
credentials: {
username: 'admin',
password: process.env.DB_PASSWORD
}
});
// Connect to database
await db.connect();
// Create a document
const user = await db.collection('users').create({
name: 'Alice Smith',
email: 'alice@example.com',
createdAt: new Date()
});
console.log('User created:', user.id);
Configuration Options
NexusDB accepts the following configuration parameters:
- host - Database host address (default: localhost)
- port - Connection port (default: 7687)
- database - Database name to connect to
- poolSize - Connection pool size (default: 10)
- timeout - Connection timeout in ms (default: 5000)
Basic Queries
Perform CRUD operations with intuitive methods:
// Read documents
const users = await db.collection('users')
.find({ status: 'active' })
.limit(10)
.toArray();
// Update document
await db.collection('users').updateOne(
{ email: 'alice@example.com' },
{ $set: { lastLogin: new Date() } }
);
// Delete document
await db.collection('users').deleteOne({
_id: userId
});
⚠️ Performance Warning
Avoid using find() without filters on large collections. Always use indexes for better performance.
Indexing Recommended
Create indexes to optimize query performance:
// Create single field index
await db.collection('users').createIndex({ email: 1 });
// Create compound index
await db.collection('orders').createIndex({
userId: 1,
createdAt: -1
});
// Create unique index
await db.collection('users').createIndex(
{ email: 1 },
{ unique: true }
);
🚨 Important
Never store sensitive data like passwords in plain text. Always use proper hashing algorithms like bcrypt or Argon2.
Next Steps
Now that you've completed the basics, explore these advanced topics:
- Learn about transactions for atomic operations
- Implement security best practices
- Optimize with performance tuning
- Scale your database with replication and sharding