Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential import collision: import path should be "go.mongodb.org/mongo-driver", not "github.com/mongodb/mongo-go-driver" #4

Open
KateGo520 opened this issue Aug 10, 2020 · 1 comment

Comments

@KateGo520
Copy link

Background

I find that go.mongodb.org/mongo-driver and github.com/mongodb/mongo-go-driver coexist in this repo:
https://github.com/longfellowone/field-services/blob/master/go.mod (Line 22 & 32)

github.com/mongodb/mongo-go-driver v1.0.1
go.mongodb.org/mongo-driver v1.0.1 // indirect

That’s because the mongodb/mongo-go-driver has already renamed it’s import path from "github.com/mongodb/mongo-go-driver" to "go.mongodb.org/mongo-driver". When you use the old path "github.com/mongodb/mongo-go-driver" to import the mongodb/mongo-go-driver, will reintroduces mongodb/mongo-go-driver through the import statements "import go.mongodb.org/mongo-driver" in the go source file of mongodb/mongo-go-driver.

https://github.com/mongodb/mongo-go-driver/blob/v1.0.1/mongo/client.go#L16

package mongo
import (
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/bsoncodec"
	…
)

The "go.mongodb.org/mongo-driver" and "github.com/mongodb/mongo-go-driver" are the same repos. This will work in isolation, bring about potential risks and problems.

Solution

Follow the requirements of mongodb/mongo-go-driver README.md:

To get started with the driver, import the mongo package, create a mongo.Client:

import (
    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/options"
)
…

Replace all the old import paths, change "github.com/mongodb/mongo-go-driver" to "go.mongodb.org/mongo-driver".
Where did you import it: https://github.com/longfellowone/field-services/search?q=github.com%2Fmongodb%2Fmongo-go-driver&unscoped_q=github.com%2Fmongodb%2Fmongo-go-driver

@KateGo520
Copy link
Author

@longfellowone Could you help me review this issue? Thx :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant