Import Mysql Table To Mongo Collection

Step1: Export Csv From Table

Step2: Write name fields in First Row

Step3: Open The Navicate , select my collection and Import Csv file To my collection

Step4: Update Collection

db.cities.find().forEach(function (doc1) {
var doc2 = db.provinces.findOne({ id: doc1.province_id });
if (doc2 != null) {
db.cities.update({'_id' : doc1._id}, [ { $set: { "m_province_id" :doc2._id} } ]);
}
});

Step5: delete column

db.cities.update({}, {$unset: {id:1}} , {multi: true});
db.cities.update({}, {$unset: {id:1}}, false, true);

Need Code:

Rename:

db.cities.update({}, {$rename: {“m_province_id”:”province_id”}} , {multi: true});

Create Collection:
db.createCollection(“countries”)
Insert Row:
db.countries.insert
(
{
“title” : “ایران”,
“code” : “irn”
}
)

Enjoy

--

--