mongo-migrate icon indicating copy to clipboard operation
mongo-migrate copied to clipboard

Support DocumentDB: removed use of 'type' field in getCollections()

Open Yoone opened this issue 6 years ago • 3 comments

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.

Yoone avatar Sep 03 '19 15:09 Yoone

Codecov Report

Merging #7 into master will decrease coverage by 0.93%. The diff coverage is 0%.

Impacted file tree graph

@@            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 data Powered by Codecov. Last update b6296c1...a21e5aa. Read the comment docs.

codecov-io avatar Sep 03 '19 15:09 codecov-io

I don't think I can add test coverage for this. It would require an AWS DocumentDB instance.

Yoone avatar Sep 03 '19 15:09 Yoone

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.

Yoone avatar Sep 04 '19 08:09 Yoone

Fixed in v0.3.0 based on commits from #5.

xakep666 avatar Mar 25 '24 11:03 xakep666