ctf0 / mysql-to-mongodb
A Console Commands To Help With Data Migration From mysql To mongodb.
Fund package maintenance!
ctf0
Requires
- php: >=5.5.9
- illuminate/support: ^5.1
- nesbot/carbon: ~1.20
Suggests
- jenssegers/mongodb: >=2.2.0
- moloquent/moloquent: dev-master
This package is auto-updated.
Last update: 2023-01-03 23:18:55 UTC
README
I made this tool as i was starting to learn mongodb and i couldnt find any decent alternative.
The tool is working as expected and even tested on a live working app that uses mysql, however i strongly recommend that you use this package with a grain of salt.
Installation
-
composer require ctf0/mysql-to-mongodb
-
(Laravel < 5.5) add the service provider
'providers' => [ ctf0\MysqlToMongoDb\MysqlToMongoDbServiceProvider::class, ]
Usage
mongo:migrate # clone mysql data to mongodb mongo:migrate:pivot # resolve pivot foreign ids (ManyToMany) mongo:migrate:relation # resolve foreign ids (OneToMany) mongo:migrate:cleanup # remove un-wanted field/collection from the db mongo:migrate:maintain # backup/restore mongo db (mongodump / mongorestore)
Notes
-
if you havent installed mongodb yet, check http://wp.me/p4DYee-9Q
-
make sure that you can connect to both of your dbs through laravel without any issues.
-
the package assume that your mysql driver connection is
mysql
and your default driver connection ismongodb
. -
the package doesnt recreate the table types from
mysql
, and its up tomongodb
to decide at that point, however currently the below types gets converted on migration-
tinyint(1) => bool
-
timestamp => date
-
multi(OneToMany) => index
-
unique => index/unique/sparse
having a field with the same name in 2 different collections will give an error, so as a-way-around the index is saved as (CollectionName_field)
-
-
all your app calls to
id
should be changed to_id
except in view which is automatically converted through the model. -
moloquent
usestring
for the relation linking/referencing, so when converting the foreign_ids toObjectId
now you will havestring
on one side andObjectId
on the other which will cause lots of trouble, so its kept as string.
ToDo
- Find Away To Add Data In Bulk Instead Of One By One.
- Upload Db Backup To S3.
- Make A Small GUI For Easier Migration.