mongorpc

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2026 License: Apache-2.0

README

MongoRPC

MongoDB + gRPC = MongoRPC

A high-performance gRPC proxy for MongoDB, enabling seamless database access from any platform.

Go Version License

Features

  • Full MongoDB Type Support - ObjectId, Decimal128, GeoPoint, UUID, Regex, and more
  • gRPC API - High-performance, strongly-typed API with streaming support
  • Aggregation Pipelines - Full MongoDB aggregation framework support
  • Transactions - ACID transaction support
  • Change Streams - Real-time data change notifications
  • Modern Go - Built with Go 1.22+, mongo-driver v2, and structured logging

Quick Start

Prerequisites
  • Go 1.22+
  • MongoDB 6.0+
  • buf (for proto generation)
Installation
# Clone the repository
git clone https://github.com/mongorpc/mongorpc.git
cd mongorpc

# Install dependencies
go mod download

# Build the server
go build -o bin/mongorpc ./cmd/server
Running the Server
# Start MongoDB (if not running)
docker run -d -p 27017:27017 --name mongodb mongo:7.0

# Run MongoRPC server
./bin/mongorpc --address localhost:50051 --mongodb-uri mongodb://localhost:27017
Configuration
Flag Environment Default Description
--address SERVER_ADDRESS localhost:50051 gRPC server address
--mongodb-uri MONGODB_URI mongodb://localhost:27017 MongoDB connection URI
--database MONGODB_DATABASE mongorpc Default database
--debug DEBUG false Enable debug logging

Client Libraries

JavaScript Example
const client = new MongoRPC("http://localhost:50051");

const document = await client
  .database("sample_mflix")
  .collection("movies")
  .document("573a13b0f29313caabd35231")
  .get();
Dart Example
var client = await mongorpc("localhost", port: 50051);
var collection = client.database("sample_mflix").collection("movies");

var documents = await collection
    .documents()
    .limit(10)
    .sort(by: "title")
    .get();

Project Structure

mongorpc/
├── cmd/server/           # Server entry point
├── gen/                  # Generated protobuf/gRPC code
├── internal/
│   ├── api/mongorpc/    # gRPC service implementations
│   ├── config/          # Configuration management
│   └── repository/      # Data access layer
│       └── mongodb/     # MongoDB client
├── proto/               # Protocol buffer definitions
│   └── mongorpc/v1/     # v1 API protos
├── buf.yaml             # Buf configuration
└── buf.gen.yaml         # Code generation config

Development

Generate Proto Code
buf generate proto
Build
go build -o bin/mongorpc ./cmd/server
Test with grpcurl
# List services
grpcurl -plaintext localhost:50051 list

# Create a document
grpcurl -plaintext -d '{
  "database": "test",
  "collection": "users",
  "document": {
    "fields": {
      "name": {"string_value": "Alice"},
      "age": {"int32_value": 30}
    }
  }
}' localhost:50051 mongorpc.v1.MongoRPC/CreateDocument

API Overview

Document Operations
  • GetDocument - Get a single document by ID
  • ListDocuments - List documents with filtering and pagination
  • CreateDocument - Create a new document
  • UpdateDocument - Update an existing document
  • DeleteDocument - Delete a document
  • BatchGetDocuments - Get multiple documents (streaming)
Query Operations
  • RunQuery - Execute queries with streaming results
  • Aggregate - Run aggregation pipelines
  • CountDocuments - Count matching documents
  • Distinct - Get distinct field values
Transaction Operations
  • BeginTransaction - Start a new transaction
  • CommitTransaction - Commit a transaction
  • AbortTransaction - Abort a transaction
Change Streams
  • Watch - Watch collection for changes
  • WatchDatabase - Watch database for changes

License

Copyright 2021-2025 MongoRPC

Licensed under the Apache License, Version 2.0

Directories

Path Synopsis
cmd
server command
MongoRPC Server - A gRPC proxy for MongoDB.
MongoRPC Server - A gRPC proxy for MongoDB.
gen
internal
api/mongorpc
Package mongorpc provides the gRPC service implementations.
Package mongorpc provides the gRPC service implementations.
config
Package config provides configuration management for MongoRPC server.
Package config provides configuration management for MongoRPC server.
middleware
Package middleware provides gRPC interceptors for MongoRPC.
Package middleware provides gRPC interceptors for MongoRPC.
observability
Package observability provides Prometheus metrics for MongoRPC.
Package observability provides Prometheus metrics for MongoRPC.
repository/mongodb
Package mongodb provides admin operations.
Package mongodb provides admin operations.
rules
Package rules provides a CEL-based security rules engine for MongoRPC.
Package rules provides a CEL-based security rules engine for MongoRPC.
service
Package service provides business logic layer between API and repository.
Package service provides business logic layer between API and repository.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL