mongodocstore

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package mongodocstore provides an implementation of the docstore API for MongoDB.

URLs

For docstore.OpenCollection, mongodocstore registers for the scheme "mongo". The default URL opener will dial a Mongo server using the environment variable "MONGO_SERVER_URL". To customize the URL opener, or for more details on the URL format, see URLOpener. See https://gocloud.dev/concepts/urls/ for background information.

As

mongodocstore exposes the following types for As:

  • Collection: *mongo.Collection
  • ActionList.BeforeDo: *options.FindOneOptions, *options.InsertOneOptions, *options.ReplaceOptions, *options.UpdateOptions or *options.DeleteOptions
  • Query.BeforeQuery: *options.FindOptions
  • DocumentIterator: *mongo.Cursor

Docstore types not supported by the Go mongo client, go.mongodb.org/mongo-driver/mongo: TODO(jba): write

MongoDB types not supported by Docstore: TODO(jba): write

Index

Constants

View Source
const Scheme = "mongo"

Scheme is the URL scheme mongodocstore registers its URLOpener under on docstore.DefaultMux.

Variables

This section is empty.

Functions

func Dial

func Dial(ctx context.Context, uri string) (*mongo.Client, error)

Dial returns a new mongoDB client that is connected to the server URI.

func OpenCollection

func OpenCollection(mcoll *mongo.Collection, idField string, opts *Options) (*docstore.Collection, error)

OpenCollection opens a MongoDB collection for use with Docstore. The idField argument is the name of the document field to use for the document ID (MongoDB's _id field). If it is empty, the field "_id" will be used.

func OpenCollectionWithIDFunc

func OpenCollectionWithIDFunc(mcoll *mongo.Collection, idFunc func(docstore.Document) interface{}, opts *Options) (*docstore.Collection, error)

OpenCollectionWithIDFunc opens a MongoDB collection for use with Docstore. The idFunc argument is function that accepts a document and returns the value to be used for the document ID (MongoDB's _id field). IDFunc should return nil if the document is missing the information to construct an ID. This will cause all actions, even Create, to fail.

Types

type Options

type Options struct {
	// Lowercase all field names for document encoding, field selection, update modifications
	// and queries.
	LowercaseFields bool
}

type URLOpener

type URLOpener struct {
	// A Client is a MongoDB client that performs operations on the db, must be
	// non-nil.
	Client *mongo.Client

	// Options specifies the options to pass to OpenCollection.
	Options Options
}

URLOpener opens URLs like "mongo://mydb/mycollection". See https://docs.mongodb.com/manual/reference/limits/#naming-restrictions for naming restrictions.

The URL Host is used as the database name. The URL Path is used as the collection name.

No query parameters are supported.

func (*URLOpener) OpenCollectionURL

func (o *URLOpener) OpenCollectionURL(ctx context.Context, u *url.URL) (*docstore.Collection, error)

OpenCollectionURL opens the Collection URL.

Jump to

Keyboard shortcuts

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