SurrealDB
SurrealDB Docs Logo

Enter a search query

Navigation
Table of Contents

Migrating from MongoDB to SurrealDB

This page details some MongoDB data types and their SurrealQL equivalents, followed by links to the Surreal Sync tool which allows data from MongoDB to be automatically imported to SurrealDB.

Data types

The following chart shows MongoDB data types along with the equivalent or near-equivalent SurrealQL data type for each.

MongoDB Data TypeBSON TypeJSON Extended Format v2SurrealDB Mapping
DoubleDouble3.14 (Relaxed) or {"$numberDouble": "3.14"} (Canonical)float
StringString"text"string
ObjectDocument{"key": "value"}object
ArrayArray[1, 2, 3]array
Binary ataBinary{"$binary": {"base64": "...", "subType": "..."}}bytes
UndefinedUndefined{"$undefined": true}none
ObjectIdObjectId{"$oid": "507f1f77bcf86cd799439011"}string
BooleanBooleantrue/falsebool
DateDateTime{"$date": "2024-01-01T00:00:00Z"} (Relaxed) or {"$date": {"$numberLong": "1672531200000"}} (Canonical)datetime
NullNullnullnull
Regular ExpressionRegularExpression{"$regularExpression": {"pattern": "...", "options": "..."}}regex
DBPointerDbPointer{"$dbPointer": {"$ref": "...", "$id": {...}}}string
JavaScriptJavaScriptCode{"$code": "function(){}"}string
SymbolSymbol{"$symbol": "text"}string
JavaScript with scopeJavaScriptCodeWithScope{"$code": "...", "$scope": {...}}object
32-bit integerInt3242 (Relaxed) or {"$numberInt": "42"} (Canonical)int
TimestampTimestamp{"$timestamp": {"t": 1672531200, "i": 1}}datetime
64-bit integerInt64{"$numberLong": "123"}int
Decimal128Decimal128{"$numberDecimal": "123.45"}number
DBRefDocument{"$ref": "users", "$id": "123"}thing
Min keyMinKey{"$minKey": 1}object
Max keyMaxKey{"$maxKey": 1}object

Importing from MongoDB using Surreal Sync

Surreal Sync can be used to export MongoDB collections to SurrealDB.

It supports inconsistent full syncs and consistent incremental syncs, and together provides ability to reproduce consistent snapshots from the source MongoDB collections onto the target SurrealDB tables.

For more on how to import data from MongoDB to SurrealDB, please see the following pages in the Surreal Sync repo.