-
Notifications
You must be signed in to change notification settings - Fork 0
Build Tools From Source
The MongoDB tools provide import, export, and diagnostic capabilities.
As of MongoDB 3.0, MongoDB tools, except for mongosniff and mongoperf, are written in Go. In order to build and contribute to them, you will need to ensure you have installed the requisite dependencies, clone the mongo-tools git repository, and build the tools.
To build mongosniff and mongoperf, see /contributors/tutorial/build-mongodb-from-source.
To build the tools, you must have Go version 1.3 or newer. You can download Go from https://golang.org/dl/.
You will also need git.
Windows users who wish to install the tools with support for SSL or SASL must also have gcc, which comes bundled with mingw. To use gcc, install mingw for 32-bit systems, or Mingw-64 for 64-bit systems, then add the path to gcc to your PATH environment variable.
-
Clone the mongo-tools repository. If you wish to push your changes to the core project, you may wish to fork the repository and clone your fork instead.
-
Set your
GOPATHto include the vendored dependencies by running theset_gopath.shorset_gopath.bathelper script from the root of themongo-toolsrepository:./set_gopath.shnote
set_gopath.batis designed for use with the Windows Command Prompt.
Build the tools with go build:
-
Create the
bindirectory where you will install the tools:mkdir bin -
Build the desired tool with
go build, specifying the destination with the-oflag and then the package to build. In this case, the destination isbin/mongoimportand the package ismongoimport/main/mongoimport.go:go build -o bin/mongoimport mongoimport/main/mongoimport.goIf you run
bin/mongoimport --version, it will return themongoimportversion (e.g. 3.0.0) and anot-built-with-ldflagsmessage for the git version. To build the desired tool with the commit gitspec, run instead:go build -ldflags "-X github.com/mongodb/mongo-tools/common/options.Gitspec `git rev-parse HEAD`" -o bin/mongoimport mongoimport/main/mongoimport.go
You can also use the -tags flag to tell go build to build the tools with support for SSL and/or SASL:
go build -o bin/mongoimport -tags ssl mongoimport/main/mongoimport.go
go build -o bin/mongoimport -tags "ssl sasl" mongoimport/main/mongoimport.go
You build the tools on Windows in much the same way as Linux/Unix users, using go build:
-
Create the
bindirectory where you will install the tools. -
From the root of the
mongo-toolsdirectory, build the desired tool withgo build, specifying the destination with the-oflag and then the package to build. In this case, the destination is\bin\mongoimport.exeand the package is\mongoimport\main\mongoimport.go:go build -o .\bin\mongoimport.exe .\mongoimport\main\mongoimport.goIf you run
.\bin\mongoimport.exe --version, it will return themongoimportversion (e.g. 3.0.0) and anot-built-with-ldflagsmessage for the git version.To build the desired tool with the commit gitspec, run instead:
for /f "delims=" %g in ('git rev-parse HEAD') do go build -ldflags "-X github.com/mongodb/mongo-tools/common/options.Gitspec %g" -o .\bin\mongoimport.exe .\mongoimport\main\mongoimport.go
If you have installed gcc, you can also use the -tags flag to tell go build to build the tools with support for SSL and/or SASL:
go build -o .\bin\mongoimport.exe -tags ssl .\mongoimport\main\mongoimport.go
go build -o .\bin\mongoimport.exe -tags "ssl sasl" .\mongoimport\main\mongoimport.go
Whenever you make changes to the tools code, you must run set_gopath.bat again before rebuilding the tools or the changes will not be captured by the build.