Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
/ MysqlToMongoDb Public archive

a simple tool to migrate data from mysql to mongodb for Laravel

License

Notifications You must be signed in to change notification settings

ctf0/MysqlToMongoDb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mysql To MongoDb
Latest Stable Version Total Downloads

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)

Wiki

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 is mongodb.

  • the package doesnt recreate the table types from mysql, and its up to mongodb 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 use string for the relation linking/referencing, so when converting the foreign_ids to ObjectId now you will have string on one side and ObjectId 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.

About

a simple tool to migrate data from mysql to mongodb for Laravel

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages