Babbu Mann Babbu Mann - 1 year ago 135
SQL Question

Getting RECORD Array in MongoDB

I imported json data from mysql using this command :

mongoimport --db your --collection categories categories.json --type json

But when i stared search data i found an issue that mongodb collection have RECORDS Array and not imported ids as object like first one.

Any one know ? how to import data from mysql to mongodb that will be as Object not an extra RECORDS Array ?

enter image description here

Answer Source

I think RECORDS is coming from your mysql, please check your JSON file by opening it in editor like sublime.

Your Answer to export from mysql to mongo with JSON Objects:

Install Gem :

gem install mysql2xxxx

Then run :

mysql2json --user=root --database=yourdb --execute "select * from categories" > cat.json

So after run above command you will get clean records in json format, don't know how you are importing but i don't think RECORDS should come.

After done this you can use :

mongoimport --db your --collection categories cat.json --type json

Hopefully this will work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download