mongo

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2019 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package mongo provides functions to trace the mongodb/mongo-go-driver package (https://github.com/mongodb/mongo-go-driver). It support v0.2.0 of github.com/mongodb/mongo-go-driver

`NewMonitor` will return an event.CommandMonitor which is used to trace requests.

Example
package main

import (
	"context"

	"github.com/mongodb/mongo-go-driver/bson"
	"github.com/mongodb/mongo-go-driver/mongo"
	"github.com/mongodb/mongo-go-driver/mongo/options"

	mongotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/mongodb/mongo-go-driver/mongo"
)

func main() {
	// connect to MongoDB
	opts := options.Client()
	opts.SetMonitor(mongotrace.NewMonitor())
	client, err := mongo.Connect(context.Background(), "mongodb://localhost:27017", opts)
	if err != nil {
		panic(err)
	}
	db := client.Database("example")
	inventory := db.Collection("inventory")

	inventory.InsertOne(context.Background(), bson.D{
		{Key: "item", Value: "canvas"},
		{Key: "qty", Value: 100},
		{Key: "tags", Value: bson.A{"cotton"}},
		{Key: "size", Value: bson.D{
			{Key: "h", Value: 28},
			{Key: "w", Value: 35.5},
			{Key: "uom", Value: "cm"},
		}},
	})
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMonitor

func NewMonitor() *event.CommandMonitor

NewMonitor creates a new mongodb event CommandMonitor.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL