Support DocumentDB: removed use of 'type' field in getCollections()
Context
I'm currently working with AWS DocumentDB as a MongoDB drop-in replacement. I noticed that mongo-migrate is using a feature that is not present in DocumentDB: the type field on db.listCollections().
I'm getting an error returned by migrate.go:getCollections() when using the following filter:
bson.D{bson.E{Key: "type", Value: "collection"}}
The DocumentDB error is: Field 'type' is currently not supported.
Fix
The fix consists in checking the error returned by the following call:
cursor, err := m.db.ListCollections(context.Background(), filter, options)
And retry without a filter (that is bson.D{}). That way, the filter still works on MongoDB, and it won't return views.
Codecov Report
Merging #7 into master will decrease coverage by
0.93%. The diff coverage is0%.
@@ Coverage Diff @@
## master #7 +/- ##
==========================================
- Coverage 80.58% 79.65% -0.94%
==========================================
Files 4 4
Lines 170 172 +2
==========================================
Hits 137 137
- Misses 19 20 +1
- Partials 14 15 +1
| Impacted Files | Coverage Δ | |
|---|---|---|
| migrate.go | 70.33% <0%> (-1.22%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update b6296c1...a21e5aa. Read the comment docs.
I don't think I can add test coverage for this. It would require an AWS DocumentDB instance.
Looking at https://github.com/xakep666/mongo-migrate/pull/5, it's probably a better approach.
Only thing is that options := options.ListCollections().SetNameOnly(true) was removed, I'm not sure why.
Fixed in v0.3.0 based on commits from #5.