DocumentationFauxDB Documentation

FauxDB API Reference

MongoDB Wire Protocol Compatibility

FauxDB implements the MongoDB wire protocol, ensuring compatibility with existing MongoDB drivers, tools, and applications.

Supported Operations

CRUD Operations

  • insertOne, insertMany
  • findOne, find
  • updateOne, updateMany
  • deleteOne, deleteMany

Advanced Features

  • Aggregation pipelines
  • Geospatial queries
  • ACID transactions
  • Indexing support

API Endpoints

FauxDB provides RESTful API endpoints for programmatic access.

Database Management

List databases

GET /api/v1/databases

Create database

POST /api/v1/databases
Content-Type: application/json

{"name": "mydb"}

Collection Management

List collections

GET /api/v1/databases/{db}/collections

Create collection

POST /api/v1/databases/{db}/collections
Content-Type: application/json

{"name": "users"}

Document Operations

Query documents

GET /api/v1/databases/{db}/collections/{collection}/documents

Insert document

POST /api/v1/databases/{db}/collections/{collection}/documents
Content-Type: application/json

{"name": "John", "email": "john@example.com"}

CRUD Operations

Basic create, read, update, and delete operations using MongoDB protocol.

MongoDB CRUD examples

# Connect with mongosh
mongosh mongodb://localhost:27018/mydb

# Insert documents
db.users.insertOne({ 
  name: "John Doe", 
  email: "john@example.com",
  age: 30
})

db.users.insertMany([
  { name: "Jane Smith", email: "jane@example.com", age: 25 },
  { name: "Bob Wilson", email: "bob@example.com", age: 35 }
])

# Find documents
db.users.find({ age: { $gte: 25 } })
db.users.findOne({ email: "john@example.com" })

# Update documents
db.users.updateOne(
  { email: "john@example.com" },
  { $set: { age: 31 } }
)

db.users.updateMany(
  { age: { $lt: 30 } },
  { $inc: { age: 1 } }
)

# Delete documents
db.users.deleteOne({ email: "john@example.com" })
db.users.deleteMany({ age: { $gte: 40 } })

Aggregation Pipelines

Complex data processing using MongoDB aggregation framework.

Aggregation examples

# Group by age and count
db.users.aggregate([
  { $group: { _id: "$age", count: { $sum: 1 } } },
  { $sort: { count: -1 } }
])

# Complex aggregation
db.orders.aggregate([
  { $match: { status: "completed" } },
  { $group: {
      _id: "$customer_id",
      total: { $sum: "$amount" },
      count: { $sum: 1 },
      avg: { $avg: "$amount" }
    }
  },
  { $sort: { total: -1 } },
  { $limit: 10 }
])

Transactions

Multi-document ACID transactions with PostgreSQL backend.

Transaction example

# Start a transaction session
session = db.getMongo().startSession()
session.startTransaction()

# Perform operations within transaction
db.users.insertOne({name: "Alice"}, {session: session})
db.profiles.insertOne({userId: "123"}, {session: session})

# Commit transaction
session.commitTransaction()

Related Documentation