Coming from MongoDB
What maps from MongoDB to Raft DB (documents, filters, indexes), what does not (wire protocol, update operators, aggregation), and how to move a collection through JSON lines.
Raft DB stores documents: a key and a JSON object, in tables (the HTTP API also accepts the word collections). That part will feel familiar. The rest of MongoDB's surface is smaller here, and a MongoDB driver cannot connect: there is no MongoDB wire protocol.
Vocabulary#
| MongoDB | Raft DB |
|---|---|
| database | database |
| collection | table (collections is accepted in HTTP paths) |
_id | the key (a string over HTTP) |
| document | document (a JSON object) |
insertOne / replaceOne with upsert | POST .../documents with {"key":..., "document":...} |
findOne({_id}) | GET .../documents/{key} |
find(filter) | POST /v1/query with a JSON filter |
countDocuments(filter) | POST /v1/query with "count": true |
deleteOne({_id}) | DELETE .../documents/{key} |
createIndex | POST .../documents/indexes |
insertMany | NDJSON import (.../import) |
Filters look alike#
The filter language uses the operators you know: $eq $ne $gt $gte $lt $lte $in $nin $exists $not $and $or, dotted names for nested fields, and $text for text search. {"age": {"$gt": 30}, "city": "Pune"} means the same here.
One difference matters: types are strict. {"age": 30} matches an integer 30, not the double 30.0 and not the text "30". Check how your data was written (see the filter language).
SQL is available too: POST /v1/query with "language": "sql" accepts a SELECT over the table.
Example#
POST /v1/databases/shop/tables/orders/documents
{"key":"o-1001","document":{"customer":"Asha","total":120,"items":[{"sku":"A1","qty":2}]}}
POST /v1/query
{"db":"shop","table":"orders","text":"{\"total\":{\"$gte\":100}}","pageSize":50}See HTTP: documents and HTTP: queries for the exact request bodies.
What is different or missing#
- No update operators. There is no
$set,$inc,$push. To change a field, read the document, change it in your code and write it back (existed: truetells you it replaced one). Two writers changing the same document at once can overwrite each other. - No aggregation pipeline.
$group,$lookup,$projectand the other stages do not exist. For grouping and joins, use the SQL front-ends (MySQL, PostgreSQL or SQL Server dialect) over the same engine, or do the work in the application. - No change streams, no GridFS, no geospatial or time-series collections.
- Keys are strings.
ObjectId, dates and decimals have no special type: store them as text or numbers and convert in your code. - Schemas are available and optional: a table can enforce a schema (documents and schemas).
- Large result sets are read in pages with a cursor, not as a server-side cursor object.
Moving the data#
- Export each collection as JSON lines with MongoDB's own tools (
mongoexportwrites one document per line by default). - Turn each line into
{"key": <the _id as text>, "document": {...the rest...}}. A short script does this; extended JSON values such as{"$oid": "..."}or{"$date": "..."}must be converted to plain text or numbers first. - Send the lines to
POST /v1/databases/{db}/tables/{t}/importin batches (a body is under 1 MiB and at most 20,000 lines). The answer lists the lines that failed. - Create the indexes you used, then compare counts:
countthrough the API againstcountDocumentsin MongoDB.
Do this on a copy, and keep MongoDB running until the application has been changed and tested.