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://godoc.org/gocloud.dev#hdr-URLs for background information.
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
- func Dial(ctx context.Context, uri string) (*mongo.Client, error)
- func OpenCollection(mcoll *mongo.Collection, idField string, _ *Options) *docstore.Collection
- func OpenCollectionWithIDFunc(mcoll *mongo.Collection, idFunc func(docstore.Document) interface{}, ...) *docstore.Collection
- type Options
- type URLOpener
Constants ¶
const Scheme = "mongo"
Scheme is the URL scheme mongodocstore registers its URLOpener under on docstore.DefaultMux.
Variables ¶
This section is empty.
Functions ¶
func OpenCollection ¶
func OpenCollection(mcoll *mongo.Collection, idField string, _ *Options) *docstore.Collection
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{}, _ *Options) *docstore.Collection
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 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.