Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/examples/connectors/mongodb/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"ok": true,
"documents": [
{
"_id": "507f1f77bcf86cd799439011",
"name": "John Doe",
"email": "john.doe@example.com",
"age": 32,
"role": "admin",
"active": true,
"createdAt": "2023-11-23T12:00:00.000Z",
"updatedAt": "2023-11-23T12:00:00.000Z",
"tags": ["premium", "verified"],
"address": {
"street": "123 Main St",
"city": "San Francisco",
"state": "CA",
"zip": "94103"
}
},
{
"_id": "507f1f77bcf86cd799439012",
"name": "Jane Smith",
"email": "jane.smith@example.com",
"age": 28,
"role": "user",
"active": true,
"createdAt": "2023-11-23T11:30:00.000Z",
"updatedAt": "2023-11-23T11:30:00.000Z",
"tags": ["verified"],
"address": {
"street": "456 Oak Ave",
"city": "New York",
"state": "NY",
"zip": "10001"
}
}
],
"count": 2
}
122 changes: 122 additions & 0 deletions docs/examples/connectors/mongodb/mock.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/env node
// Mock MongoDB exec-rpc wrapper for admission testing
// Simulates vejas-mongodb binary that accepts JSON requests on stdin

import readline from 'readline';

const users = [
{
_id: '507f1f77bcf86cd799439011',
name: 'John Doe',
email: 'john.doe@example.com',
age: 32,
role: 'admin',
active: true,
createdAt: '2023-11-23T12:00:00.000Z',
updatedAt: '2023-11-23T12:00:00.000Z',
tags: ['premium', 'verified'],
address: {
street: '123 Main St',
city: 'San Francisco',
state: 'CA',
zip: '94103'
}
},
{
_id: '507f1f77bcf86cd799439012',
name: 'Jane Smith',
email: 'jane.smith@example.com',
age: 28,
role: 'user',
active: true,
createdAt: '2023-11-23T11:30:00.000Z',
updatedAt: '2023-11-23T11:30:00.000Z',
tags: ['verified'],
address: {
street: '456 Oak Ave',
city: 'New York',
state: 'NY',
zip: '10001'
}
}
];

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});

rl.on('line', (line) => {
try {
const request = JSON.parse(line);

if (request.op === 'find') {
// Find documents
const response = {
ok: true,
documents: users,
count: users.length
};
console.log(JSON.stringify(response));
} else if (request.op === 'findOne') {
// Find one document
const response = {
ok: true,
document: users[0]
};
console.log(JSON.stringify(response));
} else if (request.op === 'insertOne') {
// Insert one document
const response = {
ok: true,
insertedId: '507f1f77bcf86cd799439013'
};
console.log(JSON.stringify(response));
} else if (request.op === 'insertMany') {
// Insert many documents
const response = {
ok: true,
insertedIds: ['507f1f77bcf86cd799439013', '507f1f77bcf86cd799439014']
};
console.log(JSON.stringify(response));
} else if (request.op === 'updateOne' || request.op === 'updateMany') {
// Update documents
const response = {
ok: true,
matchedCount: 1,
modifiedCount: 1
};
console.log(JSON.stringify(response));
} else if (request.op === 'deleteOne' || request.op === 'deleteMany') {
// Delete documents
const response = {
ok: true,
deletedCount: 1
};
console.log(JSON.stringify(response));
} else if (request.op === 'aggregate') {
// Aggregation pipeline
const response = {
ok: true,
documents: [
{ _id: 'admin', count: 1 },
{ _id: 'user', count: 1 }
]
};
console.log(JSON.stringify(response));
} else {
console.log(JSON.stringify({
ok: false,
error: `Unknown operation: ${request.op}`
}));
}
} catch (err) {
console.log(JSON.stringify({
ok: false,
error: err.message
}));
}
});

console.error('Mock MongoDB connector started');
51 changes: 51 additions & 0 deletions docs/examples/connectors/mongodb/mongodb.vjs.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# connector: mongodb — Comprehensive MongoDB database integration
#
# Platform connector for MongoDB database. Supports multiple operations:
# - Document operations (insertOne, insertMany, findOne, find, updateOne, updateMany, deleteOne, deleteMany)
# - Aggregation pipeline (aggregate with stages)
# - Index management (createIndex, listIndexes, dropIndex)
# - Collection management (listCollections, createCollection, dropCollection)
# - Bulk operations (bulkWrite)
#
# Uses exec-rpc driver wrapping a MongoDB client process. The process accepts
# JSON requests on stdin and returns JSON responses on stdout.
#
# Subjects:
# REQUEST: vxrpc.mongodb (outside vx.* namespace for request/reply)
#
# Secrets:
# mongodb/uri - MongoDB connection URI (mongodb://... or mongodb+srv://...)
# mongodb/database - Database name
#
# Rate limits: Depends on server configuration and connection pool size
# Connection pooling: Managed by the exec process
#
# Request format (JSON on stdin):
# {"op":"findOne","collection":"users","filter":{"id":123}}
# {"op":"insertOne","collection":"users","document":{"name":"John","email":"john@example.com"}}
# {"op":"updateMany","collection":"users","filter":{"active":false},"update":{"$set":{"status":"inactive"}}}
# {"op":"aggregate","collection":"orders","pipeline":[{"$match":{"status":"completed"}},{"$group":{"_id":"$customer","total":{"$sum":"$amount"}}}]}
#
# Response format (JSON on stdout):
# {"ok":true,"document":{"_id":"507f1f77bcf86cd799439011","name":"John"}}
# {"ok":true,"insertedId":"507f1f77bcf86cd799439011"}
# {"ok":true,"modifiedCount":5}
# {"ok":false,"error":"Collection not found"}
#
# Note: This connector requires a MongoDB client wrapper binary (e.g., vejas-mongodb)
# that implements the exec-rpc protocol. The binary would use a MongoDB driver
# (e.g., mongodb crate in Rust) to execute operations.

driver "exec-rpc"

# Request/reply subject (outside vx.* namespace)
REQUEST_SUBJECT = "vxrpc.mongodb"

# MongoDB client wrapper command
CMD = "/opt/vejas/vejas-mongodb"

# Environment variables for connection
ENV = {
MONGODB_URI: secret("mongodb/uri"),
MONGODB_DATABASE: secret("mongodb/database")
}
3 changes: 3 additions & 0 deletions docs/examples/connectors/mongodb/overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CMD": "node mock.mjs"
}
Loading