MongoDB data types are either fully supported via direct conversion, or partially supported via an object that maintains the information in the original type. For more on these data types, see the project repository.
Create file users.json containing data to be stored in MongoDB:
[ { "_id": { "$oid": "64a7a21fc25e3d2c7a3b55f1" }, "name": "Alice Johnson", "email": "alice@example.com", "age": 29, "roles": ["admin", "editor"] }, { "_id": { "$oid": "64a7a21fc25e3d2c7a3b55f2" }, "name": "Bob Smith", "email": "bob@example.com", "age": 35, "roles": ["user"] } ]
Next, import the data to MongoDB via the following command.
mongoimport --db testdb --collection users --file users.json --jsonArray
With the data imported, start the server at the path of your current directory.
mongod --dbpath /your/current/directory
With the MongoDB server running, start a SurrealDB server with surreal start --user root --pass root
.
The surreal-sync
command can then be used to import the data from the running MongoDB instance.
surreal-sync sync mongo-db \ --source-database "testdb" \ --to-namespace "production" \ --to-database "migrated_data" \ --source-uri "mongodb://localhost:27017"
To confirm the data, log in to the SurrealDB database under namespace production
and database migrated_data
, and use the query SELECT * FROM users
to see the data.
Result[ { age: 29, email: 'alice@example.com', id: users:64a7a21fc25e3d2c7a3b55f1, name: 'Alice Johnson', roles: [ 'admin', 'editor' ] }, { age: 35, email: 'bob@example.com', id: users:64a7a21fc25e3d2c7a3b55f2, name: 'Bob Smith', roles: [ 'user' ] } ]