mongo

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2018 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package mongo provides functions to trace the mongodb/mongo-go-driver package (https://github.com/mongodb/mongo-go-driver). The minimum required version is v0.0.13.

`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/clientopt"

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

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

	inventory.InsertOne(context.Background(), bson.NewDocument(
		bson.EC.String("item", "canvas"),
		bson.EC.Int32("qty", 100),
		bson.EC.ArrayFromElements("tags",
			bson.VC.String("cotton"),
		),
		bson.EC.SubDocumentFromElements("size",
			bson.EC.Int32("h", 28),
			bson.EC.Double("w", 35.5),
			bson.EC.String("uom", "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