MongoDB profiling: writing CLI for tracing Query Logs in GO using the new driver and go modules

The database profiler collects detailed information about Database Commands executed against a running mongod instance. This includes CRUD operations as well as configuration and administration commands. The profiler writes all the data it collects to the system.profile collection, a capped collection in the admindatabase.

You can use a tailable cursor with capped collections. Similar to the Unix tail -f command, the tailable cursor “tails” the end of a capped collection. As new documents are inserted into the capped collection, you can use the tailable cursor to continue retrieving documents.

mkdir -p ~/goprojects/mongotrace
cd ~/goprojects/mongotrace
go mod init github.com/spaiz/mongotrace
main.go
mongotrace version
mongotrace info --config="./config.local.json"
mongotrace enable --config="./config.local.json"
mongotrace tail --config="./config.local.json"
mongotrace tail --raw --indent=false --config="./config.local.json"
app.go
config.local.json
config.staging.json
config.go
type Command interface {
Execute() error
}
cmd_report.go
example for the GROUP query
go build
go mod vendor
go build -mod vendor
git init 
git add .
git commit -m "initial commit"
git remote add origin git@github.com:spaiz/mongotrace.git
git push -u origin master
git tag v0.0.2
git push --tags
make build
make install
db.mycollection.find({
name: 'Alex',
$comment: 'request-id-fe4a6604-ec0e-40ec-a72c-6f3b899b7d4b'
});

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store