This is a golang tool to extract mongodb schema. The main steps are:
- List all collections from mongdodb database
- Handle collection one by one
- Select 100 documents and analysis document's fields type according object real type. Using []bson.D as result type:
var results []bson.D err := c.Find(bson.M{}).Limit(MaxTryRecords).Sort("-_id").All(&results) - For slice []interface{}, also handle at most 100 records.
- Handle bson.D as embedded document.
- Select 100 documents and analysis document's fields type according object real type. Using []bson.D as result type:
Depends on
Sample command: extract_mgo.exe -database mongodb://db_owner:db_owner@localhost:47017/sampledb -format csv -output mongo_schema.csv